DLookup only reading top row

Miff3436

Registered User.
Local time
Today, 08:39
Joined
May 27, 2015
Messages
23
Hi all,

I have a command button on a Access 2010 form that i am using as my switchboard. On this form i have a hidden unbound text box that captures the users environ"username". When the user hits a command button on the form the code looks at the name in the hidden textbox that captures the environ"username" and then DLooks up a table to see if there is a match. If yes then it will open the next form and if not then a message box appears.

Code:
Private Sub Command6_Click()
Dim TxtUsername As String
If Me.TxtUsername = DLookup("[OneLondon Login]", "TblAccessUsers") Then
DoCmd.OpenForm "Bakerloo_Main_Form"
Exit Sub
Else
MsgBox "You do not have permission to access this database"
End If
End Sub

This works fine apart from the fact it will only read the first name entered in the table. This table(TblAccessUsers) could have up to 50 names in it and possibly have names removed and re added at a later date. Is there a way i can get the code to look up every name in the table ??. Can anyone see where i have gone wrong ?

Thanks miff3436
 
DLookup looks up ONE value, according to the criteria (which you have not specified). Look up DLookup in the documentation or help file.
 
Hi spikepl

Thanks for getting back so quick. I'm pretty new to Access and have been thrown in at the deepend a bit. Apologies if the description is not great !

The criteria i have not specified is this the table content ? If so this will be a list of names i will enter into the table that i want to have access to the db. I will enter there names into the table so that the text matches the application username that is captured when they open the db. Where is the documentation file ?

Thanks miff3436
 
The more i look at it the more it looks like the value in the switchboard textbox needs to loop through the table containing names of users. When the value meets an exact critera it will open the db. The values in the table are unique so cannot return multiple values.

I will close this thread as solved and start a new thread.


Thanks miff3436
 

Users who are viewing this thread

Back
Top Bottom