• June 13, 2021

PHSARIT

Bring Technology Ideas with you

 Create Simple Login Form Using VBA in Ms Access

By Create New Form and using some tools to design login form as below:

    • Rename Username to txtusername
    • Rename Password to txtpassword
    • Create login button
    • Create Exit button

    Use this code below

    Private Sub cmdLogin_Click()
    ' check enter data or not
    If IsNull(Me.txtusername) = True Then
        MsgBox ("Please enter your name"), vbExclamation
        Me.txtusername.SetFocus
    ElseIf IsNull(Me.txtpassword) = True Then
        MsgBox ("Please enter your password"), vbExclamation
        Me.txtpassword.SetFocus
    Else
        ' check username
        If Me.txtusername = "Tola" Then
        ' check password
            If Me.txtpassword = "123" Then
                MsgBox ("Login Successfully"), vbInformation
                'DoCmd.Close acForm, "Login", acSaveYes
                'DoCmd.OpenForm "Main", acNormal
            Else
                MsgBox ("Incorrect Password"), vbExclamation
                Me.txtpassword.SetFocus
            End If
        Else
            MsgBox ("Incorrect Username"), vbExclamation
            Me.txtusername.SetFocus
        End If
    End If
    End Sub

    Login Fail

      Login Successful

        Related post