I'm getting an error message while trying to check if a serial number already exists in my table (Access 2010).
Here's the code I'm using:
If CurrentDb.OpenRecordset("Select count(*) from Table_Name where vSerial='" & Forms!Form_Name!vSerial & "';").Fields(0) > 0 Then
MsgBox ("Serial number already in use")
Else
Me.ctrl_register.Pages(1).Enabled = True
Me.ctrl_register.Pages(1).SetFocus
End If
What am I doing wrong?
I'm using the same code with 2 different tables and I can't find the difference between them. The only difference between the tables is the number of data in them.
Could someone point me in the right direction?
The error I get is a runtime error 3464 in Access - data type missmatch in criteria expression.
The variable vSerial is defined as a number.
Thanks in advance!
On the Home tab, in the Find group, click Find. The Find and Replace dialog box appears, with the Find tab selected. In the Find What box, type the value for which you want to search. To change the field that you want to search or to search the entire underlying table, click the appropriate option in the Look In list.
In Access desktop databases you can use the DLookup function to get the value of a particular field from a specified set of records (a domain). Use the DLookup function in a Visual Basic for Applications (VBA) module, a macro, a query expression, or a calculated control on a form or report.
vSerial is integer value and you have used '' in your query, remove them. Quotes are used for string values.
If CurrentDb.OpenRecordset("Select count(*) from Table_Name where vSerial=" & Forms!Form_Name!vSerial & ";").Fields(0) > 0 Then
MsgBox ("Serial number already in use")
Else
Me.ctrl_register.Pages(1).Enabled = True
Me.ctrl_register.Pages(1).SetFocus
End If
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With