Data type mismatch in query

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have an update query that uses criteria in the id field. It is a long
variable set in one of the forms and is called DeleteID. In the query I set
the criteria field to:
=DeleteID but it changes it to "DeleteID". I run the query from the form
and get a 'data type mismatch'.

Mike J
 
mjj4golf said:
I have an update query that uses criteria in the id field. It is a long
variable set in one of the forms and is called DeleteID. In the query I set
the criteria field to:
=DeleteID but it changes it to "DeleteID". I run the query from the form
and get a 'data type mismatch'.

--
Hi Mike,
you can't use a variable in a query criteria.
This is a Workaround:
Make a function in a module like this:

public Function GetDeleteID() as Long
GetDeleteID=DeleteID
end Function

In the query use the Function GeteDeleteID() instead of DeleteID

UPDATE YourTable Set FieldX=YYYY Where ID = GetDeleteID()


Cinzia
 
Enter the criteria with brackets around the item, so Access will know you
are referring to a field.

Criteria: =[DeleteID]

To be extra safe
Criteria: =[Your Table Name with DeleteID in it].[DeleteID]
 
If the criteria for the query is a field in the form, you should use

Forms![FormName]![DeleteID]
=============================
The thing that pazzle me, if the query change automatically to "DeleteID" it
mean that the field type is string, and you said that the field type is
number.
 

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

Back
Top