Missing Syntax

shaneucc

Registered User.
Local time
Today, 20:30
Joined
Jul 25, 2013
Messages
28
This DLookup give me a missing syntax error.
Dim strName As String
strName = DLookup("Manufacturer", "ComponentT", "TotalComponent = " & Forms!ProjectF.P_AnchorCmb)
Any idea why?
 
I've never fully understood when [] are needed but most of the examples you see in explanations of DLookup have then round the field names, also they use ! Not . in the criteria, perhaps you should try a few changes.

Brian
 
I got it in the end. This is the code that worked.

Dim str As String
str = DLookup("Manufacturer", "ComponentT", "TotalComponent = '" & Forms![ProjectF]!P_AnchorCmb & "'")
 
...I've never fully understood when [] are needed...

Basically, in VBA Code, the Square Brackets are needed around Field/Control names that contain non-Alpha/Numeric characters. Using these, for this purpose, is really ill-advised. The most common violation of this is the use of Spaces in names.

In other uses, such as in Conditional Formatting, or when using the names of Controls in expressions used for the Control Source of an Unbound Control, they are always needed around the names of Controls! Also note that, in these applications, you do not precede the names with the Me. used in VBA Code.

Linq ;0)>
 
The point linq is that you see examples that do comply with good nameing but still with [] and no comment is made as to when the [] is needed, but from what you say it is no different to any other occasion in SQL or VBA.

Thanks for the response.

Brian
 

Users who are viewing this thread

Back
Top Bottom