2014-10-01 47 views
1

所以這裏是我的一個非常簡單的登錄系統代碼..訪問VBA不會讓我定義一個記錄集

每次我嘗試運行它,我都會得到; 「編譯錯誤:用戶定義類型未定義」 這是我從來沒有爲訪問凸顯了線「昏暗rsLogin作爲記錄」

見過反正繼承人的其餘代碼:

Private Sub Label15_Click() 

Dim StaffID, Password As String 
Dim Match As Integer 
Dim rsLogin As Recordset 

If IsNull(Me.Password) And IsNull(Me.StaffID) Then 
    MsgBox ("Please enter login information") 

End If 
If IsNull(Me.StaffID) Then                
MsgBox ("Please enter a Staff ID.") 

End If 
If IsNull(Me.Password) Then 
MsgBox ("Please enter a Password.") 

End If 

Match = 1 
StaffID = Me.StaffID                
Password = Me.Password 

Set rsLogin = CurrentDb.OpenRecordset("tblStaff", dbOpenDynaset)     
rsLogin.MoveFirst 

Do Until rsLogin.EOF = True               
    If rsLogin!StaffID = StaffID And rsLogin!Password = Password Then 
     gblUser = rsLogin!StaffID           
     Match = 2                 
     Exit Do 
    Else 
     rsLogin.MoveNext                
    End If 
Loop 

If Match = 1 Then 
MsgBox ("Incorrect StaffID and/or Password.")        
ElseIf Match = 2 Then                 
DoCmd.Close 
DoCmd.OpenForm ("frmMain") 

End If 


End Sub 

任何幫助將是偉大的!

感謝與DAO

+0

你在哪裏定義'Recordset'? – APerson 2014-10-01 13:11:09

+0

訪問版本? ADO或DAO? – GSerg 2014-10-01 13:12:35

+0

結果由CurrentDb分配,因此它期望一個DAO記錄集。 – Barry 2014-10-01 13:13:42

回答

0

嘗試前綴是:

dim rsLogin as DAO.Recordset 

還要檢查,如果沒有引用丟失。缺少引用(引用但未出現/安裝)也會導致最基本的內置函數發生編譯器錯誤。

+0

剛剛編輯了代碼,沒有任何更改。多麼奇怪 – Hsimmson 2014-10-01 13:21:42

+0

Debug> compile給出了相同的錯誤?已經嘗試過緊湊/修復? – Barry 2014-10-01 13:27:17