VBA code for Dlookup and Yes/No Checkbox

jrosen12

New member
Local time
Today, 10:42
Joined
May 1, 2014
Messages
2
Hello,

I'm trying to find a code that will allow me to check a value of a yes/no checkbox based on a username.

What I want to happpen is:
1. The code looks to see if the username that is entered in "txtUsername" field on the form matches the "empUsername" value on the table "tblUsers."
2. If there is a match, I want it to look at the value for the field "Admin" on "tblUsers" to see if the value is checked as true.
3. If the value is true, I want it to open a specific form "frmAdmin." If it is false, I want it to open a form "frmMain."

I've been toying around with some VBA codes I've found in google searches, but it is not recognizing the Admin field and instead taking all users into the frmMain.

Help would be greatly appreciated!
 
Sometimes False and True are stored as 0 ad -1.
Show your code + some sample data from the table "tblUsers".
 
Hi

Perhaps something like....


Code:
  If Dlookup("empUsername", "tblUsers", "empUsername =" & txtUsernamevaluehere & "") Is Not Null Then ' check username matches
           If Dlookup(same as above but for the checkbox) = True Then
                  Load frm Admin ' so this point username matches and they are an so we open admin frm
           Else
                  Load frmMain ' username is a match but admin isn't, so open main
           End if
     msgbox "Username not found" ' username not found then do something else here
End if
Might be better to dim Admin as boolean and then do
admin = dlookup("Admin", "tblUsers", "empUsername = " & txtUsernameValueHere) which will return true or false depending on whether or not the checkbox is ticked and use that in the code so it reads easier

Should put you on the right path? If you can't get it to work plz post a stripped copy and can take a look, gl!
 
Last edited:
As a suggestion to change your Admin tick box to an Admin Level as an integer - this would give you the ability to have different access levels rather than just one...
 

Users who are viewing this thread

Back
Top Bottom