Help with syntax error

H

Hoopster

Hey guy's. I've gotten myself lost here. I have VBA Code that I know I have a
syntax error in but can't for the life of me get it right. My code is for a
DLookup and goes like this:

varRate = DLookup("[Rate]", "[OperationRate]", "[StyleID] = '" & _
Me.[StyleID] & "' And [OperationID] = '" & Me.[OperationID] & "' And_
[DepartmentID] = '" & Me.[DepartmentID] & "'")

All Controls Rate, StyleID, OperationID and DepartmentID are Number Format.
Can somebody out there take a look?

Thanks much in advance
Steve
 
F

fredg

Hey guy's. I've gotten myself lost here. I have VBA Code that I know I have a
syntax error in but can't for the life of me get it right. My code is for a
DLookup and goes like this:

varRate = DLookup("[Rate]", "[OperationRate]", "[StyleID] = '" & _
Me.[StyleID] & "' And [OperationID] = '" & Me.[OperationID] & "' And_
[DepartmentID] = '" & Me.[DepartmentID] & "'")

All Controls Rate, StyleID, OperationID and DepartmentID are Number Format.
Can somebody out there take a look?

Thanks much in advance
Steve

If all 3 fields used in the where clause are Number datatype fields,
try:

varRate = DLookup("[Rate]", "[OperationRate]", "[StyleID] = " & _
Me.[StyleID] & " And [OperationID] = " & Me.[OperationID] & " And _
[DepartmentID] = " & Me.[DepartmentID])

Only Text variables need to be surrounded with single quotes.
Also your last continuation character was not preceded by a space.
 
H

Hoopster

Mr. fredg,

Thank you so very much sir. It worked like a charm..... :)

Steve

fredg said:
Hey guy's. I've gotten myself lost here. I have VBA Code that I know I have a
syntax error in but can't for the life of me get it right. My code is for a
DLookup and goes like this:

varRate = DLookup("[Rate]", "[OperationRate]", "[StyleID] = '" & _
Me.[StyleID] & "' And [OperationID] = '" & Me.[OperationID] & "' And_
[DepartmentID] = '" & Me.[DepartmentID] & "'")

All Controls Rate, StyleID, OperationID and DepartmentID are Number Format.
Can somebody out there take a look?

Thanks much in advance
Steve

If all 3 fields used in the where clause are Number datatype fields,
try:

varRate = DLookup("[Rate]", "[OperationRate]", "[StyleID] = " & _
Me.[StyleID] & " And [OperationID] = " & Me.[OperationID] & " And _
[DepartmentID] = " & Me.[DepartmentID])

Only Text variables need to be surrounded with single quotes.
Also your last continuation character was not preceded by a space.
 
K

Klatuu

You have a line continuation character (_) inside the qoutes. It has to be
outside the quotes and your syntax is for text fields. You do not use
delimiters for numeric fields:

varRate = DLookup("[Rate]", "[OperationRate]", "[StyleID] = " & _
Me.[StyleID] & " And [OperationID] = " & Me.[OperationID] & _
" And [DepartmentID] = " & Me.[DepartmentID])
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top