设为首页收藏本站Access中国

Office中国论坛/Access中国论坛

 找回密码
 注册

QQ登录

只需一步,快速开始

实现查询功能(DAO)

1970-1-1 08:00| 发布者: 佚名| 查看: 1771| 评论: 0

On Error GoTo 100
If TextBox1.Text = "" Then
MsgBox "请输入姓名", 1 + 16, "系统提示"
TextBox1.SetFocus
Else
    Dim RS1 As Recordset
    Dim DB1 As Database
    Set DB1 = OpenDatabase(ThisWorkbook.Path & "\" & "学生档案.MDB")
    Set RS1 = DB1.OpenRecordset(Name:="档案", Type:=dbOpenDynaset)
         RS1.FindFirst "姓名='" & TextBox1.Value & "'"
         If RS1.NoMatch = True Then
         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, "系统提示"





On Error GoTo 100
If TextBox1.Text = "" Then
MsgBox "请输入姓名", 1 + 16, "系统提示"
TextBox1.SetFocus
Else
    Dim RS1 As Recordset
    Dim DB1 As Database
    Set DB1 = OpenDatabase(ThisWorkbook.Path & "\" & "学生档案.MDB")
    Set RS1 = DB1.OpenRecordset(Name:="档案", Type:=dbOpenDynaset)
         RS1.FindFirst "姓名='" & TextBox1.Value & "'"
         If RS1.NoMatch = True Then
         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, "系统提示"




别人笑我太疯癫,我

最新评论

相关分类

QQ|站长邮箱|小黑屋|手机版|Office中国/Access中国 ( 粤ICP备10043721号-1 )  

GMT+8, 2024-4-28 22:04 , Processed in 0.072394 second(s), 16 queries .

Powered by Discuz! X3.3

© 2001-2017 Comsenz Inc.

返回顶部