DLookup for Unbound CheckBox (1 Viewer)

burrina

Registered User.
Local time
Today, 17:09
Joined
May 10, 2014
Messages
972
Having a Senior Moment!

On my Login form I am trying to get the status of a user. Form and checkbox are unbound.

tblUserSecurity_Sec
userID is the UserName.
Field (Active) Data Type is Number, Field Size is Integer

CheckBox is (chkactive)


If DLookup("[Active]", "tblUserSecurity_Sec") = -1 And [userID] = (Me.txtUserID) Then
Me.chkactive = -1
End If

Thanks for your time.
 

burrina

Registered User.
Local time
Today, 17:09
Joined
May 10, 2014
Messages
972
Thanks, but that does not help. I can get the value of Active but not if I add the matching userID . Simple, I know but frustrating.
 

vbaInet

AWF VIP
Local time
Today, 23:09
Joined
Jan 22, 2010
Messages
26,374
Did you look at the examples in the link? The way the DLookup is constructed in those examples are different from yours. Please read the examples.
 

burrina

Registered User.
Local time
Today, 17:09
Joined
May 10, 2014
Messages
972
I have spent hours on this simple thing with every combination to make it work.

Thanks Anyway. YES, I read that a LONG time ago.
 

vbaInet

AWF VIP
Local time
Today, 23:09
Joined
Jan 22, 2010
Messages
26,374
Still no luck?

Ok, let's look at your code and go through it. tblUserSecurity_Sec is your table right? And the UserID field is a text field containing the user ID you're checking against?

What is the -1 in your code supposed to mean?
 

burrina

Registered User.
Local time
Today, 17:09
Joined
May 10, 2014
Messages
972
-1 means the users active status is Active. 0 is InActive.
 

vbaInet

AWF VIP
Local time
Today, 23:09
Joined
Jan 22, 2010
Messages
26,374
I'm talking about the -1 in the DLookup() line of your code. What were you trying to do there?
Code:
If DLookup("[Active]", "tblUserSecurity_Sec")[B][COLOR="Red"] = -1[/COLOR][/B] And [userID] = (Me.txtUserID) Then
 

burrina

Registered User.
Local time
Today, 17:09
Joined
May 10, 2014
Messages
972
If the users status is Active (-1) and the userID (UserName) matches txtUserID (UserName) then check off the check box chkactive.
 

vbaInet

AWF VIP
Local time
Today, 23:09
Joined
Jan 22, 2010
Messages
26,374
Re-construct your code along the lines of:
Code:
If DLookup("Active", "tblUserSecurity_Sec", "userID = '" &  Me.txtUserID & "'") And Me.chkactive = -1 Then
    Msgbox "I'm active"
End If
Test it using a Msgbox as above.
 

burrina

Registered User.
Local time
Today, 17:09
Joined
May 10, 2014
Messages
972
This worked.

If DLookup("Active", "tblUserSecurity_Sec", "userID = '" & Me.txtUserID & "'") And Me.txtstatus = -1 Then
Me.chkactive = -1
End If


Thanks for you help and patience.
 
Last edited:

Users who are viewing this thread

Top Bottom