PDA

View Full Version : Solved: DLookup Annoyance,(wrong # of args)



Trevor
04-09-2008, 11:45 AM
my DLookup is supose to lookup the username from the IndividualSettingsTbl based on the computer account username then msg the user Name but I keep getting wrong # of args error and Dlookup is highlighted. The table has no evtries so I should get the "N/A" msgbox.

Dim UsrName As String
Dim AccountName As String
AccountName = Environ("UserName")
UsrName = Nz(DLookup("UserName", "IndividualSettingsTbl", "UserName = '", AccountName), "N/A")
If UsrName = "N/A" Then
MsgBox UsrName
End If
End Sub

Thanks for helping

Qubit
04-09-2008, 12:46 PM
I notice that you are using a single quote, but don't have one at the end:
..."UserName = '", AccountName, which probably should be:
..."UserName = ' " & AccountName & "'" - which looks messy & hard to read.

To guard against apostrophe's fouling things up (like 'O'Brien'), I wrote a WrapQuote(strText) function which just puts a CHR$(34) before & after the strText var and returns it. you could then write:
..."UserName = " & WrapQuote(AccountName)...

.q

Trevor
04-09-2008, 12:55 PM
I solved it, I just noticed your post as I was postin this Qubit

Dim UsrName As String
Dim AccountName As String
MsgBox "this is test"
AccountName = Environ("UserName")
UsrName = Nz(DLookup("UserName", "IndividualSettingsTbl", "UserName = '" & AccountName & "'"), "N/A")
If UsrName = "N/A" Then
MsgBox "This is a test " & UsrName
End If
End Sub

it was a puncuation error