Solved Dlookup syntax issues (1 Viewer)

Shecky

New member
Local time
Today, 15:52
Joined
Jul 29, 2021
Messages
25
Good day.
Having issues getting the syntax correct on this AfterUpdate event featured on one of my forms.

The code I am trying :
Private Sub SKU_AfterUpdate()
Me.[Product Description] = DLookup("ProductDescription", "Products", "SKU = " & Forms![Orders2].[Order Details Subform4].[SKU].Column(0))
End Sub

What I want:
On my subform, which enters data into my order details, I would like the 'Products Description' (yes has a space in the name) to be the result of a Dlookup for the matching SKU number in my products table.
afterupdate.png

Products.png


I tried a lot of variations but can not get anything that does not generate an error on the AfterUpdate event.
I need to save the Product Description to retain what was ordered at the time, as product descs can change overtime.
Please any help?
 

Attachments

  • 1646676186869.png
    1646676186869.png
    6.9 KB · Views: 156

Gasman

Enthusiastic Amateur
Local time
Today, 20:52
Joined
Sep 21, 2011
Messages
14,273
Strings need to be surrounded by single quotes ' unless it contains a single quote, then triple double quotes works, I think?

Dates with # and in mm/dd/yyyy or yyyy-mm-dd format

Numbers do not need anything

I tend to put the criteria into a string variable for domain functions if not a single simple criteria.

Then I can debug.print them to see if I have the syntax correct.

The when correct, I can use them in the function.

Plus, if you cannot see the error, you can copy and paste here or elsewhere, so someone can point out the error.?
 

plog

Banishment Pending
Local time
Today, 14:52
Joined
May 11, 2011
Messages
11,646
Since SKU is text you need to match it like its text in the Dlookup. That means surrounding the value you are supplying with single quotes:

..."SKU = '" & Forms![Orders2].[Order Details Subform4].[SKU].Column(0)) & "'"
 

Shecky

New member
Local time
Today, 15:52
Joined
Jul 29, 2021
Messages
25
I am still getting a "object doesnt support this property or Method" error
 

Shecky

New member
Local time
Today, 15:52
Joined
Jul 29, 2021
Messages
25
Is syntax proper on the...
Me.[Product Description] =

Is the fact that the Product Description control is a dropdown that selects from a query an issue?
 

Shecky

New member
Local time
Today, 15:52
Joined
Jul 29, 2021
Messages
25
I have changed Product Description to a textbox and changed the code on SKU event AfterUpdate to:
Me.[Product Description] = DLookup("ProductDescription", "Products", "SKU = '" & Forms![Orders2].[Order Details Subform4].[SKU] & "'"
Now gives me this error...
error.png
 

Gasman

Enthusiastic Amateur
Local time
Today, 20:52
Joined
Sep 21, 2011
Messages
14,273
You would need .form after the subform control
 

Users who are viewing this thread

Top Bottom