Microsoft Access创建ACCDE文件

时间:2014-04-15 12:17:33

标签: vba ms-access

这是我的第一篇文章,我正在尝试从我的数据库创建一个accde数据库文件,我不断收到错误消息&我决定仔细查看我的VBA代码,运行调试并且我一直收到错误编译错误方法或找不到数据成员。我的代码在下面任何帮助非常感谢!在此先感谢

Option Compare Database

Private Sub Command1_Click()

    Dim UserLevel As Integer
    Dim TempPass As String
    Dim ID As Integer
    If IsNull(Me.txtLoginID) Then
        MsgBox "Please Enter LoginID", vbInformation, "LoginID Required"
        Me.txtLoginID.SetFocus
    ElseIf IsNull(Me.txtpassword) Then
        MsgBox "Please Enter Password", vbInformation, "Password Required"
        Me.txtpassword.SetFocus
    Else
        'process the job
        If (IsNull(DLookup("UserLogin", "tblUser", "UserLogin='" & Me.txtLoginID.Value & "'"))) Or _
        (IsNull(DLookup("Password", "tblUser", "Password='" & Me.txtpassword.Value & "'"))) Then
            MsgBox "Incorrect LoginID or Password"
        Else
            UserLevel = DLookup("UserSecurity", "tblUser", "UserLogin = '" & Me.txtLoginID.Value & "'")
            TempPass = DLookup("password", "tblUser", "password = '" & Me.txtpassword.Value & "'")
            ID = DLookup("UserID", "tblUser", "UserLogin = '" & Me.txtLoginID.Value & "'")
            DoCmd.Close
            If (TempPass = "password") Then
                MsgBox "Please Change Your Password", vbInformation, "New Password Required"
                DoCmd.OpenForm "tblUser", , , "[UserID] = " & ID
            Else
                If UserLevel = 1 Then
                'MsgBox "Login Sucussfull"
                DoCmd.OpenForm "Admin Navigation Form"
                Else
                    If UserLevel = 2 Then
                    'MsgBox "Login Sucussfull"
                    DoCmd.OpenForm "Area Director Navigation Form"
                        If UserLevel = 2 Then
                        DoCmd.LockNavigationPane -1
                        Else
                            DoCmd.OpenForm "Area Director Navigation Form"
                        End If
                    End If
                End If
            End If
        End If
    End If

End Sub

1 个答案:

答案 0 :(得分:0)

它可能是txtLoginID的数据类型。它是文本还是数字字段?如果是number,请删除DLookUps中的单引号,如下所示:

一个:

DLookup("UserSecurity", "tblUser", "UserLogin = '" & Me.txtLoginID.Value & "'")

变化:

DLookup("UserSecurity", "tblUser", "UserLogin = " & Me.txtLoginID.Value)

查看代码的其他附注:

  1. 将按钮控件的'Command1'名称更改为不太通用的名称,以便更好地参考和维护代码。
  2. 控制字段末尾的.Value是多余的,因为它是默认的文本属性。
  3. 考虑拆分第一个If Then逻辑,查找缺少的ID和密码,并在输出消息框后使用'Exit Sub'。太多嵌套的Ifs可能很麻烦,无法调试并遵循所有可能的逻辑路径。