0
votes

I am checking table records for duplicates using Recordset. I have this code in about 5 forms with exactly same settings, but on one of them corde doesn't work - I'm receiving error 3464 : "Data type mismatch in criteria expresion":

Dim rs As Recordset

Set rs = CurrentDb.OpenRecordset("MyTable", dbOpenSnapshot)
rs.FindFirst "[Field_With_Numbers] = " & Me![Field_With_Numbers]

What is wrong ?? The only difference from other forms is that this both fields are Text and they store numbers. Any other alternatives, please advise !

1
I'm not certain of the exact syntax, as it's been a while, but you need to convert the numeric value to string. I think it might be something along the lines of rs.FindFirst "[Field_With_Numbers] = " & CStr(Me![Field_With_Numbers]) but like I said that might not be entirely correct.user2366842
I agree with @user2366842 if what you have in the tables is numbers and the field you have in the form with the error then you need to convert it back to the proper format that the table can accept.SunRay
Thanks for response. Weird, code did execute in first run, but now error again. Should I make something wit table data too - "[Field_With_Numbers]=" ?LuckyLuke82
Another thing to mention - Debugger shows "[Field_With_Numbers]=" "500", so It shows correctly ?!?...Is there any other option, problem is that I use this code for checking duplicates from Import of DB that converts all number in Excel to "Number stored as text", so I need all tables to be Text in those fields.LuckyLuke82

1 Answers

0
votes

If the field is a text field, you need to treat it as such, no matter what it actually stores.

rs.FindFirst "[Field_With_Numbers] = '" & Me![Field_With_Numbers] & "'"