By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,510 Members | 1,497 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,510 IT Pros & Developers. It's quick & easy.

Referencing to form's field value in query

P: n/a
In my query I'm trying to reference to a numeric (autonumber) field of my
form but I can't get it to work. Error message: "Datatypes don't match in
the criterium expression."
This is the particular line that doesn't work:

strSQL = strSQL & "WHERE (((Contact.ID_contact)='" & Me.ID_contact] & "'));"

When I replace '" & Me.ID_contact] & "' by 1 it works. I tried removing and
replacing the quotes in all kinds of ways, but no luck.

The '" & Me.ID_contact] & "' has always worked for me on text fields.

Can someone enlighten me?
Thanks in advance,
john
Feb 24 '07 #1
Share this Question
Share on Google+
2 Replies


P: n/a
Try:
strSQL = strSQL & "WHERE (Contact.[ID_contact] = " & _
Nz(Me.[ID_contact],0) & ");"

That:
- Removes the quotes (which are not required as delimiters on Number
fields.)
- Fixes the mismatched square brackets.
- Handles the case where the text box might is null (e.g. at a new record.)

--
Allen Browne - Microsoft MVP. Perth, Western Australia
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.

"John" <jo@hn.comwrote in message
news:er***********@textnews.wanadoo.nl...
In my query I'm trying to reference to a numeric (autonumber) field of my
form but I can't get it to work. Error message: "Datatypes don't match in
the criterium expression."
This is the particular line that doesn't work:

strSQL = strSQL & "WHERE (((Contact.ID_contact)='" & Me.ID_contact] &
"'));"

When I replace '" & Me.ID_contact] & "' by 1 it works. I tried removing
and replacing the quotes in all kinds of ways, but no luck.

The '" & Me.ID_contact] & "' has always worked for me on text fields.

Can someone enlighten me?
Thanks in advance,
john
Feb 24 '07 #2

P: n/a
Excellent! thanks a lot.
john

"Allen Browne" <Al*********@SeeSig.Invalidschreef in bericht
news:45**********************@per-qv1-newsreader-01.iinet.net.au...
Try:
strSQL = strSQL & "WHERE (Contact.[ID_contact] = " & _
Nz(Me.[ID_contact],0) & ");"

That:
- Removes the quotes (which are not required as delimiters on Number
fields.)
- Fixes the mismatched square brackets.
- Handles the case where the text box might is null (e.g. at a new
record.)

--
Allen Browne - Microsoft MVP. Perth, Western Australia
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.

"John" <jo@hn.comwrote in message
news:er***********@textnews.wanadoo.nl...
>In my query I'm trying to reference to a numeric (autonumber) field of my
form but I can't get it to work. Error message: "Datatypes don't match in
the criterium expression."
This is the particular line that doesn't work:

strSQL = strSQL & "WHERE (((Contact.ID_contact)='" & Me.ID_contact] &
"'));"

When I replace '" & Me.ID_contact] & "' by 1 it works. I tried removing
and replacing the quotes in all kinds of ways, but no luck.

The '" & Me.ID_contact] & "' has always worked for me on text fields.

Can someone enlighten me?
Thanks in advance,
john

Feb 24 '07 #3

This discussion thread is closed

Replies have been disabled for this discussion.