我尝试在Access 2010中使用VBA来创建登录表单,但我遇到了错误消息:
运行时错误(424)对象需要。
任何人都可以帮助我吗?
代码是:
Dim dbs As Database
Dim rstUserPwd As Recordset
Dim bFoundMatch As Boolean
Set dbs = CurrentDb
Set rstUserPwd = dbs.OpenRecordset("users")
bFoundMatch = False
If rstUserPwd.RecordCount > 0 Then
rstUserPwd.MoveFirst
' check for matching records
Do While rstUserPwd.EOF = True
' ERROR occurs on next line ...
If rstUserPwd![user_name] = login.txtName.Value And rstUserPwd![Password] = login.txtPass.Value Then
bFoundMatch = True
Exit Do
End If
rstUserPwd.MoveNext
Loop
End If
If bFoundMatch = True Then
'Open the next form here and close this one
DoCmd.Close acForm, Me.Name
DoCmd.OpenForm "frmNavigation"
Else
'
MsgBox "Incorrect Username or Password"
End If
rstUserPwd.Close
答案 0 :(得分:0)
它在哪里打破? 在不知情的情况下,我要做的第一件事就是添加“dim dbs as database”。出于某种原因,它可能没有隐含地看到这一点。检查工具,参考,并确保选中DAO库。
编辑添加 -
在阅读了有关代码中断位置的回复后,我认为您的登录表单已损坏。试试这些恢复方法 - http://www.datawright.com.au/access_resources/recovering_corrupted_form_or_report.htm