473,473 Members | 1,750 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Referencing to form's field value in query

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
2 8286
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: William Wisnieski | last post by:
Hello Everyone, Access 2000 I have a main form with a continuous subform. On the main form I have a text box that references a field on the subform. What I'd like it to do is show the value...
25
by: Lyn | last post by:
Hi, I am working on a genealogy form. The only table (so far) lists everybody in the family, one record per person. Each record has an autonum ID. The parent form (frmMainForm) displays the...
5
by: tdmailbox | last post by:
I have a form with a child form. In the child form there is a list of names that can grow quite large. On the parent form I want to display the first name from the child form. I set up a test...
2
by: Rooksarii | last post by:
Hello folks, Let me first apologize for any impropper terminology I may use as I am presently trying to broaden my Office knowledge by diving into Access head on. My specific problem is this....
3
by: shumaker | last post by:
This code from the subform works for getting the value of a field of the main form named "WorkSheet": MsgBox Form_WorkSheet.Recordset.Fields("Clerk").Value Each record in the mainform datasheet...
6
by: George Slamowitz | last post by:
Hello all I have a HTML control generated by the following: INPUT TYPE="hidden" NAME="MyAnswer" VALUE="" Is there a way to reference the Value of this control using VB program code??? ...
11
by: ozTinker | last post by:
I'm sure this shouldn't be too difficult, but I lack familiarity with the MS object model. Suppose I have a table "Purchase_Orders" and a form "TEMP" which I am using to look up a customer's...
2
by: sbettadpur | last post by:
Hi everybody, Hi iam strugling with more than one submit buttons with in one form here is my code <form method="post" action="Offer.php" name='issueFrm' onSubmit="return fullOfferfields();">...
8
by: angi35 | last post by:
Hi all - I've been working on this from various angles for days, and I'm pretty well stumped at this point. Hope someone has some ideas. Working in Access 2000... I’m trying to write code to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.