Cannot get a DLookUp to work

fedebrin

New Member
Joined
Jan 3, 2013
Messages
10
I have a form that updates some records by pulling fata from 2 other tables.

The first event worked with no issue pulling the brand from the "Items" table (It looks for the "ItemID" to match the records:

Private Sub ItemID_AfterUpdate()
Me![Brand] = DLookup("Brand", "Items", "[ItemID] = " & Nz(Me.ItemID, 0))
End Sub


Now, to pull the "Price" from the "Services" table it is giving me trouble. This one references the "ServiceNameID" to look up the price.




Private Sub ServiceNameID_AfterUpdate()
Me![Price] = DLookup("Price", "Services", "[ServiceNameID] = " & Nz(Me.ServiceNameID, 0))
End Sub

Any help is welcome!
 

Excel Facts

What is the last column in Excel?
Excel columns run from A to Z, AA to AZ, AAA to XFD. The last column is XFD.
What kind of trouble is it giving you exactly?
If error messages, what are they?
If unexpected results, what are they?

Also, it would be helpful to know the structure and field names of your "Services" table.
 
Upvote 0
Hello,

Getting a syntax error (missing operator) in query expression '[ServiceNameID] =

The objective is to populate the "OrderDetails" form / table with data from the "Services" & "Items" table.

I am able get data from the "Items" table with the below event:

Private Sub ItemID_AfterUpdate()
Me![Brand] = DLookup("Brand", "Items", "[ItemID] = " & Nz(Me.ItemID, 0))
End Sub

I can get the "Order Details" populated with the "Brand" with no issue.


When I try to obtain the price by entering the "ServiceNameID", I get the syntax error.

This is the event:

Private Sub ServiceNameID_AfterUpdate()
Me![Price] = DLookup("Price", "Services", "[ServiceNameID] = " & Nz(Me.ServiceNameID, 0))
End Sub


The format of the fields are all the same so not sure why it is not working.

thanks!
 
Upvote 0
Make sure that there are no extra spaces at the beginning of end of your field names.
If there are not any, please list the Names and Data Types of all the Fields in your Services table for us to see.
 
Last edited:
Upvote 0
Is there always only one price for a servicenameID? What is the datatype of ServiceNameID? Can you give an example of a specific ServiceNameID and the values in the table [Services]?

Also beware that specific syntax error messages are not always accurate. The error could be somewhere else and this is just where the compiler finally gets stuck. Comment out the three lines for the sub ServiceNameID_AfterUpdate() and see if it compiles without it.
 
Last edited:
Upvote 0
all fields have the same name and format
It is impossible for multiple fields to have the same name.

I will ask a 3rd time, please list the actual field names and data format for this table.
Without that knowledge, short of having access to the database, I don't know what more I can do for you.
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,181
Members
453,022
Latest member
Mohamed Magdi Tawfiq Emam

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top