Data type mismatch in query

M

mjj4golf

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
 
C

Cinzia

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
 
J

John Spencer

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]
 
O

Ofer

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.
 
Top