如何将MS-Access上的成功登录链接到新表单

时间:2015-01-03 19:17:20

标签: database ms-access ms-access-2013

我创建了一个数据库,其中包含用于登录系统的编码,但我不知道如何设置成功登录以链接到另一个表单,即主菜单。

以下是我使用的当前代码,请告知我们需要采取的进一步措施。 谢谢

Private Sub btnOK_Click()

If IsNull(Me.txtUsername) Then
    MsgBox "Please enter your username.", vbInformation, "Username Is Required"
    Me.txtUsername.SetFocus
Else
    If IsNull(Me.TxtPassword) Then
        MsgBox "Please enter your password.", vbInformation, "Password Is Required"
        Me.TxtPassword.SetFocus
    Else
        If (IsNull(DLookup("[Username]", "Employee_Login_Details", "[Username] ='" & Me.txtUsername.Value & "' And password = '" & Me.TxtPassword.Value & "'"))) Then
            MsgBox "Incorrect username or password. Please try again.", vbInformation, "Incorrect Login Details"
        Else
            MsgBox "Correct username and password.", vbInformation, "Correct Login Details"
        End If
    End If
End If
End Sub
Private Sub txtUsername_Click()

1 个答案:

答案 0 :(得分:0)

您可以使用DoCmd.OpenForm方法从一个表单导航到其他表单。我做了一些代码更改,希望也有帮助。

Private Sub btnOK_Click()
    If Len(Me.txtUsername & vbNullString) = 0 Then
        MsgBox "Please enter your username.", vbInformation, "Username Is Required"
        Me.txtUsername.SetFocus
    Else
        If Len(Me.TxtPassword & vbNullString) = 0 Then
            MsgBox "Please enter your password.", vbInformation, "Password Is Required"
            Me.TxtPassword.SetFocus
        Else
            If DCount("*", "Employee_Login_Details", "[Username] ='" & Me.txtUsername & "' And password = '" & Me.TxtPassword & "'") = 0 Then
                MsgBox "Incorrect username or password. Please try again.", vbInformation, "Incorrect Login Details"
            Else
                MsgBox "Correct username and password.", vbInformation, "Correct Login Details"
                DoCmd.OpenForm "yourFormName"
                'Optional, but is normally a good practice to hide the Login Form over closing it down completely.'
                Me.Visible = False
            End If
        End If
    End If
End Sub