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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Dlookup trouble

Status
Not open for further replies.

RufussMcGee

Technical User
Jan 7, 2005
117
0
0
US
My form "frmNewContact" has a VBA code on open.

Dim varX As Variant
varX = DLookup("[ID]", "[tblCustomer List]", "[Bill-To Name] =" _
& Forms![frmNewContact]!txtMYCustomer)


In the table "tblCustomer List" ID is the primary key field and "Bill-to Name" is the text field.

This is the error I am getting...

Syntax error (missing operator) in query expression '[Bill-To Name]=Lane Supply

The company name is spelled right, I am at a lost of the error.
Thanks
 
You need the quotes around the variable (Forms![frmNewContact]!txtMYCustomer)

"[Bill-To Name] =""" _
& Forms![frmNewContact]!txtMYCustomer) & """

Not tested

djj
The Lord is My Shepard (Psalm 23) - I need someone to lead me!
 
Sorry no go now it says...

Syntax error in string in query expression '[Bill-To Name]="Lane Supply'.
 
Try & Forms![frmNewContact]!txtMYCustomer) & chr(34)

djj
The Lord is My Shepard (Psalm 23) - I need someone to lead me!
 
ok this works somewhat the only problem is does not matter what company I pick the value is always 1. What I need to get is the ID (Primary key, autonumber) from said table.

txtLCD_ID.Value = DLookup("ID", "tblCustomerList", (Chr(34) & "[Bill-to Name] = " & "Forms!frmAlphabet!txtMYCustomer" & Chr(34)))
 
how about:

txtLCD_ID.Value = DLookup("ID", "tblCustomerList", "[Bill-to Name] = '" & Forms!frmAlphabet!txtMYCustomer & "'" )
 
Those are single quotes

='" & Forms!frmAlphabet!txtMYCustomer & "'
 
How are ya xhat . . .\

[blue]MajP[/blue] has hit on an area that can cause problems if some your names include a single quote (known as an apostrophe) as in [blue]O'Connell[/blue]. To correct this the code changes to:
Code:
[blue]txtLCD_ID = DLookup("ID", "tblCustomerList", "[Bill-to Name] = '" & Replace(Forms!frmAlphabet!txtMYCustomer,"[red][b]'[/b][/red]","[red][b]''[/b][/red]") & "'")[/blue]
[blue]Your Thoughts? . . .[/blue]

See Ya! . . . . . .

Be sure to see thread181-473997 [blue]Worthy Reading![/blue] [thumbsup2]
Also faq181-2886 [blue]Worthy Reading![/blue] [thumbsup2]
 
Actually I was not even considering that issue. The original recommendations were just incorrect.

This does not work because of the double quotes
"[Bill-To Name] =""" _
& Forms![frmNewContact]!txtMYCustomer) & """

And the next recommendation was wrong
Try & Forms![frmNewContact]!txtMYCustomer) & chr(34)
And the interpretation was wrong
(Chr(34) & "[Bill-to Name] = " & "Forms!frmAlphabet!txtMYCustomer" & Chr(34)))
 
MajP . . .

Understood! [thumbsup2]

See Ya! . . . . . .

Be sure to see thread181-473997 [blue]Worthy Reading![/blue] [thumbsup2]
Also faq181-2886 [blue]Worthy Reading![/blue] [thumbsup2]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top