以下的程序是以姓名来查询各个项目,我想用Textbox2中的年龄来查询其它各项,如何更改。先谢了!
Private Sub CommandButton3_Click() '查询
TextBox2.Value = ""
TextBox4.Value = ""
TextBox5.Value = ""
TextBox6.Value = ""
On Error GoTo 100
If TextBox1.Text = "" Then
MsgBox "请输入姓名", 1 + 16, "系统提示"
TextBox1.SetFocus
Else
Dim DB1 As Database '数据库变量
Dim RS1 As Recordset '纪录集变量
Set DB1 = OpenDatabase(ThisWorkbook.Path & "\" & "学生档案.MDB")
Set RS1 = DB1.OpenRecordset(Name:="档案", Type:=dbOpenDynaset)
RS1.FindFirst "姓名='" & TextBox1.Value & "'"
If RS1.NoMatch = True Then '假如不匹配=true
MsgBox "对不起,没有该记录"
RS1.Close
Exit Sub
Else
TextBox2.Value = RS1.Fields("年龄").Value
TextBox4.Value = RS1.Fields("性别").Value
TextBox5.Value = RS1.Fields("籍贯").Value
TextBox6.Value = RS1.Fields("联系电话").Value
End If
RS1.Close
Set RS1 = Nothing
Set DB1 = Nothing
End If
Exit Sub
100:
MsgBox "找不到符合条件的记录", 1 + 16, "系统提示"
End Sub
4nlmVjNY.rar
(249.62 KB, 下载次数: 130)
|