Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Lookup Value in a Table and Open Form

Status
Not open for further replies.

66tigger40

Technical User
May 26, 2004
108
0
0
GB
Hi

I have a simple User Information Table that based on the login I want to open one of three forms.

The AccessLevel can be either Full, Part or Activity. I have the first part working fine to check the userid against the userinformation tabel to can't get it to open the form based on the AccessLevel - missing something from the code and going round in circles!

Code:
Private Sub cmdLogin_Click()


Dim UserAccess As Variant


    If IsNull(Me.UserLogin) Or Me.UserLogin = "" Then
      MsgBox "You must enter a User Name.", vbOKOnly, "Required Data"
        Me.UserLogin.SetFocus
        Exit Sub
    End If



    If IsNull(Me.UserPassword) Or Me.UserPassword = "" Then
      MsgBox "You must enter a Password.", vbOKOnly, "Required Data"
        Me.UserPassword.SetFocus
        Exit Sub
    End If

    If Me.UserPassword.Value = DLookup("UserPassword", "tbl_UserInformation", _
            "[UserID]=" & Me.UserLogin.Value) Then

        UserID = Me.UserLogin.Value
        UserAccess = DLookup("[AccessLevel]", "Tbl_UserInformation", "[UserID] =" & Me.UserLogin.Value)
    Else
      

       MsgBox "Password Invalid. Please Try Again", vbOKOnly, _
            "Invalid Entry!"
        Me.UserPassword.SetFocus
    Exit Sub
    

    End If
        
    If UserAcess = "Full" Then
    DoCmd.Close acForm, "Frm_Login", acSaveNo
    DoCmd.OpenForm "Frm_MainMenu"
    End If
    
    
    
    If UserAccess = "Part" Then
    DoCmd.Close acForm, "Frm_Login", acSaveNo
    DoCmd.OpenForm "Frm_MainMenuPart"
    
    End If
    
    
    If UserAccess = "Activity" Then
    DoCmd.Close acForm, "Frm_Login", acSaveNo
    DoCmd.OpenForm "Frm_MainMenuActivity"
   
    End If
    



    intLogonAttempts = intLogonAttempts + 1
    If intLogonAttempts > 3 Then
      MsgBox "You do not have access to this database.Please contact admin.", _
               vbCritical, "Restricted Access!"
        Application.Quit
    End If
    
    

End Sub

Thanks for any pointers!

 
Hi there,
I see a typo in:

If UserAcess = "Full" Then
If UserA[r]c[/r]cess = "Full" Then

Just a suggestion. Instead of:
If IsNull(Me.UserLogin) Or Me.UserLogin = "" Then
You can use: If Trim(Me.UserLogin) & "" = ""

And Bob, thanx a lot for the code for distributing front ends on your site. Works great.





Pampers [afro]
Keeping it simple can be complicated
 
Eh, I mean
I see a typo in:

If UserAcess = "Full" Then

Shoud be:

If UserAccess = "Full" Then

Just a suggestion. Instead of:
If IsNull(Me.UserLogin) Or Me.UserLogin = "" Then
You can use: If Trim(Me.UserLogin) & "" = ""

Other suggestion:
Use Option Explicit (just below Option Compare Database)

Pampers [afro]
Keeping it simple can be complicated
 
G'day mate,

Look at the bottom three if statements:

Eg.
Code:
If UserAcess = "Full" Then
    DoCmd.Close acForm, "Frm_Login", acSaveNo
    DoCmd.OpenForm "Frm_MainMenu"
End If

I'd recommend opening your target form [bold]BEFORE[/bold] closing the one that's executing code ;)

Code:
If UserAcess = "Full" Then
    [red]DoCmd.OpenForm "Frm_MainMenu"
    DoCmd.Close acForm, "Frm_Login", acSaveNo[/red]
End If

Good luck!

JB
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top