Dlookup syntax error #3 Please :-)))

A

Alain

Hi to all again,

Can anybody let me know on how to fix this syntax error on the Dlookup
function, Access is pointing the error at the (#" right after the AND, no
matter what I do I am getting the error syntax elsewhere in the criteria

temp2 = DLookup("[Annual OMT]", "Budget BasicRental", "[idbranch] = " & num
& ") _
AND (#" & Format(omtdate, "mm\/dd\/yyyy") & "# Between [from] And [to])"


Many thanks again

Alain
 
G

Guest

I am fairly new to VB, but I seem to have trouble with line breaks in the
middle of a string. I would put:
& _
") AND (#"
not
& ") _
AND (#"
 
R

Roger Carlson

The Format function will convert the date into a string. But because you
have the #, the interpreter thinks it should be a date. You also have a
problem with parenthases. I'd try it without the Format function at all and
remove the inner parenthases:

temp2 = DLookup("[Annual OMT]", "Budget BasicRental", "[idbranch] = " & num
& _
" AND #" & omtdate & "# Between [from] And [to])"

--
--Roger Carlson
Access Database Samples: www.rogersaccesslibrary.com
Want answers to your Access questions in your Email?
Free subscription:
http://peach.ease.lsoft.com/scripts/wa.exe?SUBED1=ACCESS-L
 
A

Alain

Hi Roger,

I tried your suggestion and , yes again, still getting a syntax error. it
looks like this function hates me :)))

Alain


Roger Carlson said:
The Format function will convert the date into a string. But because you
have the #, the interpreter thinks it should be a date. You also have a
problem with parenthases. I'd try it without the Format function at all
and
remove the inner parenthases:

temp2 = DLookup("[Annual OMT]", "Budget BasicRental", "[idbranch] = " &
num
& _
" AND #" & omtdate & "# Between [from] And [to])"

--
--Roger Carlson
Access Database Samples: www.rogersaccesslibrary.com
Want answers to your Access questions in your Email?
Free subscription:
http://peach.ease.lsoft.com/scripts/wa.exe?SUBED1=ACCESS-L


Alain said:
Hi to all again,

Can anybody let me know on how to fix this syntax error on the Dlookup
function, Access is pointing the error at the (#" right after the AND, no
matter what I do I am getting the error syntax elsewhere in the criteria

temp2 = DLookup("[Annual OMT]", "Budget BasicRental", "[idbranch] = " & num
& ") _
AND (#" & Format(omtdate, "mm\/dd\/yyyy") & "# Between [from] And [to])"


Many thanks again

Alain
 
J

John Vinson

Hi Roger,

I tried your suggestion and , yes again, still getting a syntax error. it
looks like this function hates me :)))

Alain


Roger Carlson said:
The Format function will convert the date into a string. But because you
have the #, the interpreter thinks it should be a date. You also have a
problem with parenthases. I'd try it without the Format function at all
and
remove the inner parenthases:

temp2 = DLookup("[Annual OMT]", "Budget BasicRental", "[idbranch] = " &
num
& _
" AND #" & omtdate & "# Between [from] And [to])"

I think Roger may have misplaced a parenthesis. Try

" AND #" & omtdate & "# Between [from] And [to]")

This assumes that your table has fields named omtdate, From and To.
Otherwise - where are From and To coming from?

John W. Vinson[MVP]
Join the online Access Chats
Tuesday 11am EDT - Thursday 3:30pm EDT
http://community.compuserve.com/msdevapps
 
A

Alain

Thanks John,

I will try this solution although I recheck all the parentheses yesterday
and I tought I place the missing one at the right place.
My table contain fields From and To and the omtdate is a variable containing
a manual input

Alain


John Vinson said:
Hi Roger,

I tried your suggestion and , yes again, still getting a syntax error. it
looks like this function hates me :)))

Alain


Roger Carlson said:
The Format function will convert the date into a string. But because
you
have the #, the interpreter thinks it should be a date. You also have a
problem with parenthases. I'd try it without the Format function at all
and
remove the inner parenthases:

temp2 = DLookup("[Annual OMT]", "Budget BasicRental", "[idbranch] = " &
num
& _
" AND #" & omtdate & "# Between [from] And [to])"

I think Roger may have misplaced a parenthesis. Try

" AND #" & omtdate & "# Between [from] And [to]")

This assumes that your table has fields named omtdate, From and To.
Otherwise - where are From and To coming from?

John W. Vinson[MVP]
Join the online Access Chats
Tuesday 11am EDT - Thursday 3:30pm EDT
http://community.compuserve.com/msdevapps
 
J

John Vinson

Thanks John,

I will try this solution although I recheck all the parentheses yesterday
and I tought I place the missing one at the right place.
My table contain fields From and To and the omtdate is a variable containing
a manual input

What's the datatype of omtdate in the Dim statement? Note that it
should be formatted with mm/dd/yyyy or an unambiguous format such as
yyyy-mmm-dd.

John W. Vinson[MVP]
Join the online Access Chats
Tuesday 11am EDT - Thursday 3:30pm EDT
http://community.compuserve.com/msdevapps
 

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

Similar Threads

Dlookup & criteria No 2 7
Syntax error with function 1
Syntax error 2
DLookup Syntax Error 3
Using Max or DMax in DLookUp criteria? 1
Syntax Error 4
Syntax error on Dlookup Function 6
Dlookup error 13 7

Top