Missing Syntax (1 Viewer)

shaneucc

Registered User.
Local time
Today, 13:54
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?
 

Brianwarnock

Retired
Local time
Today, 13:54
Joined
Jun 2, 2003
Messages
12,701
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
 

shaneucc

Registered User.
Local time
Today, 13:54
Joined
Jul 25, 2013
Messages
28
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 & "'")
 

missinglinq

AWF VIP
Local time
Today, 08:54
Joined
Jun 20, 2003
Messages
6,423
...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)>
 

Brianwarnock

Retired
Local time
Today, 13:54
Joined
Jun 2, 2003
Messages
12,701
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

Top Bottom