2014-10-01 85 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