DLookup locates records on top row only

arcticsponge

VB makes me crazy
Local time
Today, 08:22
Joined
Oct 20, 2009
Messages
12
Hi All,
I am using Dlookup to allow for user access using the popular "advapi32.dll" referenced as "fOSUsername" however, when I perform the lookup using fOSUsername or even a hard-coded reference, Dlookup only returns values from the first row.

The code I am using is simple enough:


Code:
Private Sub Command74_Click()
Dim user As String

user = fOSUserName
If user = DLookup("user", "quser") Then
 
 MsgBox "The lookup was successful", vbInformation
 
 Else
 
 MsgBox "Try again", vbExclamation
 
 End If
End Sub

The table / query are identical and show as:

admin user
Administrator Arcticsponge
Tom Fred

The DLookup will find the first row users (Administrator / Arcticsponge) but none other
 
by default, all domain functions do this. use the WHERE clause to lookup any other values in the sets.
 
This is by design. DLookup() returns the value of one field in one record. The full syntax of the function is
Code:
DLookup(field, table, criteria)
If you do not specify any 'criteria' then you get the value of 'field' in the first record of 'table'.
 
I tried to enter a criteria but each time it would fall over with a 2001 "You Cancelled the previous operation" error . Can you tell me what my criteria should be.
 
Last edited:

Users who are viewing this thread

Back
Top Bottom