我試圖用VBA在2010年進入創建登錄表單,但我經歷了一個錯誤信息:訪問對象所需
運行時錯誤(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
什麼是'login.txtName'? – HansUp
就像下面的評論所說,知道斷點會有很大幫助,但這裏有兩個猜測。首先,login.txtname應該可能有一個表單!在它前面。你也可以使用me.txtnames。其次,您可能需要在前兩行中指定ado.database和ado.recordset。 – Gene
login是表單的名稱,txtName是用於輸入用戶名的文本字段的名稱 –