【问题标题】:Microsoft Access Creating an ACCDE fileMicrosoft Access 创建 ACCDE 文件
【发布时间】:2014-06-02 00:01:43
【问题描述】:

这是我的第一篇文章,我正在尝试从我的数据库创建一个 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

【问题讨论】:

  • 错误发生在哪一行?
  • Option Explicit 添加到代码顶部并编译它(调试 --> 编译)。
  • 此部分已突出显示。 .txtLoginID & enderland 我试过你说的 & 用 Explicit 替换比较数据库,但它不起作用

标签: vba ms-access


【解决方案1】:

可能是txtLoginID的数据类型。它是文本字段还是数字字段?如果是数字,则删除 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”。太多嵌套的 If 可能会导致调试和遵循所有可能的逻辑路线很麻烦。

【讨论】:

    猜你喜欢
    • 2015-01-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-02-20
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多