运行时错误91 对象变量或者with块变量未设置
求帮忙搞定这个程序PrivateSub查找_Click()Dimrst1AsRecordsetDimtempAsStringstrsearchname=InputBox(...
求帮忙搞定这个程序
Private Sub 查找_Click()
Dim rst1 As Recordset
Dim temp As String
strsearchname = InputBox("输入要查找的工号", "查找输入")
temp = " select * from 员工信息表 where 工号 like '" & strsearchname & " '"
Set rst1 = db.OpenRecordset(temp) ’程序运行至此处提示错误
If rst1.EOF Then
Do While rst1.EOF
MsgBox "找到了!"
工号.Value = rst1("工号")
姓名.Value = rst1("姓名")
岗位.Value = rst1("岗位")
薪金.Value = rst1("薪金")
工龄.Value = rst1("工龄")
附注.Value = rst1("附注")
rst1.MoveNext
Loop
Else
MsgBox "没找到"
End If
rst1.Close
End Sub 展开
Private Sub 查找_Click()
Dim rst1 As Recordset
Dim temp As String
strsearchname = InputBox("输入要查找的工号", "查找输入")
temp = " select * from 员工信息表 where 工号 like '" & strsearchname & " '"
Set rst1 = db.OpenRecordset(temp) ’程序运行至此处提示错误
If rst1.EOF Then
Do While rst1.EOF
MsgBox "找到了!"
工号.Value = rst1("工号")
姓名.Value = rst1("姓名")
岗位.Value = rst1("岗位")
薪金.Value = rst1("薪金")
工龄.Value = rst1("工龄")
附注.Value = rst1("附注")
rst1.MoveNext
Loop
Else
MsgBox "没找到"
End If
rst1.Close
End Sub 展开
展开全部
Private Sub 查找_Click()
Dim rst1 As Recordset
Dim temp As String
strsearchname = InputBox("输入要查找的工号", "查找输入")
temp = "select * from 员工信息表 where 工号 like '" & strsearchname & "'"
Set rst1 = db.OpenRecordset(temp)
'估计db没有对象引用,可能在别的模块中已经定义了,把当前模块中的定义去掉看看。
If Not rst1.EOF Then '有记录话,Eof应该为假
MsgBox "找到了!" '不要放在循环中,
Do until rst1.EOF
工号.Value = rst1("工号") '这些好像是重复写到同一个变量当中,循环不多余的吗
姓名.Value = rst1("姓名")
岗位.Value = rst1("岗位")
薪金.Value = rst1("薪金")
工龄.Value = rst1("工龄")
附注.Value = rst1("附注")
rst1.MoveNext
Loop
Else
MsgBox "没找到"
End If
rst1.Close
End Sub
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询