会员登录 - 用户注册 - 网站地图 Office中国(office-cn.net),专业Office论坛
当前位置:主页 > 技巧 > Access技巧 > 编程心得绝招 > 实际编程 > 正文

实现查询功能(DAO)

时间:2006-11-22 22:20 来源:网络 作者:佚名 阅读:
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, "系统提示"




别人笑我太疯癫,我

(责任编辑:admin)

顶一下
(0)
0%
踩一下
(0)
0%
发表评论
请自觉遵守互联网相关的政策法规,严禁发布色情、暴力、反动的言论。
评价: