Link to home
Start Free TrialLog in
Avatar of jjc9809
jjc9809

asked on

I need some help in how to reference a field name in my tblemployee for Login.

Hi everyone,

I have an Access 2007 database where I have setup a Lonin form called CreateLogin.  The information that is entered into the Create Logon form goes to a table called tblEmployees.  I have the following fields in the tblEmployees:

lngEmpID          AutoNumber
strEmpName     Text
strEmpPassword     Text
StrAccess          Text

I have a form called "CreateLogin" that lets the user put in their strEmpName, strEmpPassword, and strAccess.  The field strAccess will always be admin or user.

I need an If statement to check the table and see if the strAccess is Admin and if so open a form called StartupScreen, if not open a form called "StartUpScreen1.

I have this coding but, I do not know how to make Access know what strAccess is.  When I reference strAccess in an If Statement.  

My coding is this:


If Me.txtPassword.Value = DLookup("strEmpPassword", "tblEmployees", "[lngEmpID]=" & Me.cboEmployee.Value) Then

        lngMyEmpID = Me.cboEmployee.Value
       
        End If

'Close logon form and open splash screen
              'If strAccess = "admin" Then
  DoCmd.Close acForm, "frmLogon", acSaveNo
        DoCmd.OpenForm "StartupScreen"

     Else
        DoCmd.OpenForm "StartupScreen1"
 
End If


How can I fix this.  When I Dim strAccess as String, access stsill does not know what strAcess is


Do you have some sample coding in VBA that will do what I want to do here.

jjc9809
Avatar of Dale Fye
Dale Fye
Flag of United States of America image

How about something like:

Dim varAccess as variant
Dim strCriteria as string

strCriteria = "[lngEmpID] = " & me.cboEmployee.Value & " AND [strEmpPassword] = " & chr$(34) & me.txtPassword.Value

varAccess = DLookup("strAccess", "tblEmployees", strCriteria)
If isnull(varAccess) then
    msgbox "Invalid EmployeeID/Password combination"
    Exit Sub
Elseif varAccess = "admin" Then
    DoCmd.OpenForm "StartupScreen"
Else
    DoCmd.OpenForm "StartupScreen1"
End If

Oops, that should be:

strCriteria = "[lngEmpID] = " & me.cboEmployee.Value & " AND [strEmpPassword] = " & chr$(34) & me.txtPassword.Value & chr$(34)

ASKER CERTIFIED SOLUTION
Avatar of mbizup
mbizup
Flag of Kazakhstan image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial