Stuck with SQL Script

garyholc

Registered User.
Local time
Today, 20:28
Joined
Jul 15, 2008
Messages
64
I'm getting a "criteria mismatch" error when trying to execute some code, im sure it has something to do with the formatting of the field but cant see where.

I have a table called T_locks which I want to record the record number, username and date and time opened for files in a multiuser environment.

When the form is opened, the following script runs, and it runs ok with no problems:

recnumber = Me.Record_Number
user_name = UserName
opened = Date & " " & Time

DoCmd.RunSQL "insert into t_locks (locked_record_number,user,opendatetime) values ('" & recnumber & "','" & user_name & "','" & opened & "');"


When the user presses the exit button on the form, I want to remove that record number and username from the table again.... So the script I have for this is:

recnumber = Me.Record_Number
user_name = UserName

docmd.runsql "delete * from t_locks where locked_record_number = '" & recnumber & "' and user = '" & user_name & "';"

Its then it throws the mismatch error. I tried putting CLNG around the record number but still didnt work.

In the T_Locks table, the record number is set to Long Integer
In the Main table in which the form pulls its record number from, the field is set to Long Integer (autonumber) so both fields are the same type

So I dont really see why it is throwing an error here. Ive also tried removing the " from around the recnumber but this doesnt work. Ive put a msgbox before the delete statement and it is definately showing the correct number and username...

Ideas?
 
Ahh its ok I fixed it, I removed the ' symbols from the record number and it worked. Duh!!
 

Users who are viewing this thread

Back
Top Bottom