Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

DLookUp - (Am I going Mad?!) 2

Status
Not open for further replies.

SiJP

Programmer
May 8, 2002
708
GB
What the heck does this mean??!!

Code:
Run-time error '2471':

The expression you entered as a query parameter produced this error: "The object doesn't contain the Automation object 'admin'."

I'm running the following code in the On_Open event of a report:

Code:
Dim strUser As String
Dim strFirstName As String
Dim strLastName As String

strUser = CurrentUser
strFirstName = DLookup("[FirstName]", "UserDetails", "[UserID] = " & strUser)
strLastName = DLookup("[LastName]", "UserDetails", "[UserID] = " & strUser)

The code breaks on strFirstName... I have a table called UserDetails, a field called FirstName & a field called UserID... so whats the problem?! Its got to be somthing really basic that'll make me feel a right plum, but I can cope with that if I can get it solved! (btw, I'm logged in as "admin" therefore strUser will be 'admin')...

TIA
 
Missing the single quotes...

strFirstName = DLookup("[FirstName]", "UserDetails", "[UserID] = '" & strUser & "'")
strLastName = DLookup("[LastName]", "UserDetails", "[UserID] = '" & strUser & "'" )

I know...it's simple [smile]

[pipe]
Daniel Vlas
Systems Consultant
 
You are testing for a numeric value in your function.

Try this
strFirstName = DLookup("[FirstName]", "UserDetails", "[UserID] = '" & strUser & "'")

Paul
 
Yep.. I feel like a plum.. thank you both!
 
LOL You had the answer in your own original post (last line, admin is surrounded by quotes in both places):

logged in as "admin" therefore strUser will be 'admin'

It's funny how little things can drive one nuts (one misplaced slash made me crazy [mad]for 2 entire days. It was even funnier because no error popped up[smile] and I really felt like killing myself)

[pipe]
Daniel Vlas
Systems Consultant
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top