主题:求助!
要实现学籍的查询功能,代码如下,可是输入项目后点确定总是出现窗体显示没有该学生的记录。麻烦各位高手帮忙看看,错在哪里。
Private Sub Command1_Click()
Dim aa As Integer
txtsql = ""
If Trim(Text1.Text) <> "" Then
aa = 1
If txtsql = "" Then
txtsql = "学生档案.姓名='" & Trim(Text1.Text) & "'"
Else
txtsql = txtsql & "and 学生档案.姓名='" & Trim(Text1.Text) & "'"
End If
End If
If Trim(Combo1.Text) <> "" Then
aa = 1
If txtsql = "" Then
txtsql = "学生档案.性别='" & Trim(Combo1.Text) & "'"
Else
txtsql = txtsql & "and 学生档案.性别='" & Trim(Combo1.Text) & "'"
End If
End If
If Trim(Combo2.Text) <> "" Then
aa = 1
txtsql = ""
txtsql = "学生档案.入学时间 like '%" & Trim(Combo2.Text) & "%'"
End If
If aa = 0 Then
ss = MsgBox("你至少要输入一个条件以上才能查询!", , " 警告")
Text1.SetFocus
Exit Sub
End If
Dim str As String
str = "select * from 学生档案 where " & txtsql
Dim mrc As ADODB.Recordset
Set mrc = ExecuteSQL(str)
If mrc Is Nothing Then
zzz = MsgBox("对不起,没有此学生的档案记录!", vbOKOnly, "查询")
Frm_FindDangA.ZOrder (0)
Frm_FindDangA.Text1.SetFocus
Exit Sub
End If
End Sub
Private Sub Command2_Click()
Unload Me
End Sub
Private Sub Form_Activate()
find = True
End Sub
Private Sub Form_LostFocus()
Unload Me
End Sub
Private Sub Form_Unload(Cancel As Integer)
find = False
End Sub
Private Sub Command1_Click()
Dim aa As Integer
txtsql = ""
If Trim(Text1.Text) <> "" Then
aa = 1
If txtsql = "" Then
txtsql = "学生档案.姓名='" & Trim(Text1.Text) & "'"
Else
txtsql = txtsql & "and 学生档案.姓名='" & Trim(Text1.Text) & "'"
End If
End If
If Trim(Combo1.Text) <> "" Then
aa = 1
If txtsql = "" Then
txtsql = "学生档案.性别='" & Trim(Combo1.Text) & "'"
Else
txtsql = txtsql & "and 学生档案.性别='" & Trim(Combo1.Text) & "'"
End If
End If
If Trim(Combo2.Text) <> "" Then
aa = 1
txtsql = ""
txtsql = "学生档案.入学时间 like '%" & Trim(Combo2.Text) & "%'"
End If
If aa = 0 Then
ss = MsgBox("你至少要输入一个条件以上才能查询!", , " 警告")
Text1.SetFocus
Exit Sub
End If
Dim str As String
str = "select * from 学生档案 where " & txtsql
Dim mrc As ADODB.Recordset
Set mrc = ExecuteSQL(str)
If mrc Is Nothing Then
zzz = MsgBox("对不起,没有此学生的档案记录!", vbOKOnly, "查询")
Frm_FindDangA.ZOrder (0)
Frm_FindDangA.Text1.SetFocus
Exit Sub
End If
End Sub
Private Sub Command2_Click()
Unload Me
End Sub
Private Sub Form_Activate()
find = True
End Sub
Private Sub Form_LostFocus()
Unload Me
End Sub
Private Sub Form_Unload(Cancel As Integer)
find = False
End Sub