Conditional Macros for Login Form

Access_Help

Registered User.
Local time
Today, 12:26
Joined
Feb 12, 2005
Messages
136
Hello All.

I am an absolute beginner to Macros so please consider this when replying :D

I need to create a macro which simply checks whether the username and password entered on the form matches the one in a table in the database. If it matches then it takes you to a specified form otherwise returns a message saying 'incorrect username name and password'.

I require this urgently, replies appreciated!

Thanks
:(
 
^ Thanks. I was actually trying to use conditional formatting to avoid coding.I have found another way round it :D.
 
Here is an example of my login screen behing my login button


Code:
    Static LogonAttempts As Integer
    Dim SaiCurrentUser As String

    SaiCurrentUser = ""
    If Me.Password.Value = DLookup("[Password]", "[User Name]", "[User Name] = '" & Me.User_name & "'") Then
        SaiCurrentUser = [User Name]

        DoCmd.Close acForm, "Login Screen", acSaveNo
        DoCmd.OpenForm "Switchboard"
 
    Else
        LogonAttempts = LogonAttempts + 1
        MsgBox "Password Invalid. Please Try Again", vbOKOnly, _
               "Invalid Entry!"
        Me.Password.SetFocus
        Me.Password.Value = ""
 
 
    End If
    If LogonAttempts > 3 Then
        MsgBox "You do not have permission to access this database.Please contact your database administrator."
        Application.Quit
    End If
 

Users who are viewing this thread

Back
Top Bottom