User Rank

emdiesse

Registered User.
Local time
Today, 11:49
Joined
Feb 1, 2006
Messages
36
I have a logon script for my logon form. This is it (It works):
Code:
Private Sub cmdLogon_Click()
    ' Set up variables
    Dim dbs As Database
    Dim userstable As DAO.Recordset
    Dim logonusername
    Dim logonpassword

    'get data from the logon form
    logonusername = Trim(Forms![frmLogon]![txtusername])
    logonpassword = Trim(Forms![frmLogon].[txtpassword])

    ' open database
    Set db = CurrentDb()

    'open the table
    Set userstable = db.OpenRecordset("tblUsers", dbOpenDynaset)

    'find the users name
    userstable.FindFirst "username = '" & logonusername & "'"
    If userstable.Fields("username") = logonusername Then
       If userstable.Fields("password") = logonpassword Then
                DoCmd.OpenForm ("frmMenu")
    Else
          MsgBox "Incorrect Password"
       End If
    Else
      MsgBox "Incorrect Username"
    End If
End Sub

Within tblUsers I have:
Field Name | Data Type | Additional Info
username | text
password | text
rank | text | lookup

within frmUsers I have:
Name
txtUsername
txtPassword
txtConPas
cmboRank

When the user logs on I would like to add some code that will set a variable as the type of user that is logged on. So later I can customise the menus depending upon the rank of the user that is logged on. How do I do this?

Thanks
 
Use a global variable eg, pubRank and set this value at time user logs in.

Now use the value in this variable whenever you need to know his rank.
 
Summerwind said:
Use a global variable eg, pubRank and set this value at time user logs in.

Now use the value in this variable whenever you need to know his rank.

Like this?
Code:
Option Compare Database
Public Rank As String

Private Sub cmdLogon_Click()
    ' Set up variables
    Dim dbs As Database
    Dim userstable As DAO.Recordset
    Dim logonusername
    Dim logonpassword

    'get data from the logon form
    logonusername = Trim(Forms![frmLogon]![txtusername])
    logonpassword = Trim(Forms![frmLogon].[txtpassword])

    ' open database
    Set db = CurrentDb()

    'open the table
    Set userstable = db.OpenRecordset("tblUsers", dbOpenDynaset)

    'find the users name
    userstable.FindFirst "username = '" & logonusername & "'"
    If userstable.Fields("username") = logonusername Then
       If userstable.Fields("password") = logonpassword Then
                Rank = usertable.Fields("rank")
                DoCmd.OpenForm ("frmMenu")
    Else
          MsgBox "Incorrect Password"
       End If
    Else
      MsgBox "Incorrect Username"
    End If
End Sub

I'm not really sure how do do that could someone explain it to me?

Also, will that still be available when the form is closed to use in another form? because thats the plan.
 

Users who are viewing this thread

Back
Top Bottom