Populating fields in a form - DLOOKUP

  • Thread starter Thread starter maneor
  • Start date Start date
M

maneor

Guest
Hello,

I have problems using the Dlookup function in Access 2003 to populate the fields on the form when the user searchs for a record and finds it.

This is my basic form layout:
A text box called txtStoreId used for the search criteria and a button btnFindStore next to it. When the user selects this form, initially txtStoreId is empy, but on the fields I try to populate a # Name? appears.

For example in my txtStoreName field, I used this on the DataSource property of the control:
=Dlookup("[StoreName]", "tlbStore", "StoreId = '" &"[txtStoreId]" & "'")

I deleted the code for the button btnFindStore, perhaps I need to add some code here.

Any help will be greatly appreciated it!

Thanks,

Mane

P.S. I would like to attach my db but I didn't see the option.
 
Are you sure your source table is called "tlbStore"? Perhaps it is really "tblStore".
 
You're correct, my table is called tblStore, I just typed it wrong. Still, I'm having issues with the DLOOKUP function.
 
Perhaps this syntax will work:
Code:
=Dlookup("[StoreName]", "tblStore", "StoreId = " & [txtStoreId])
You only need the quotation marks around a field reference if the contents are text. If the contents are numeric, then the syntax above should work. If the contents re text, then try this:
Code:
=Dlookup("[StoreName]", "tblStore", "StoreId = '" & [txtStoreId]& "'")
On the other hand, perhaps you shouldn't be using Dlookup to populate form fields? How about binding the form to a query or table, or setting the form's recordsource dynamically via VBA?
 

Users who are viewing this thread

Back
Top Bottom