Hi,
Im new to VB. Im just trying to do a simple if statement that will open a specific form based on user input. The database requires me to scan in a barcode from a card. I then want to check if that barcode number is already in the database. to do this i have tried the following code.

Private Sub Barcode_AfterUpdate()
Dim curDatabase As Object
Dim tblStore_Barcode As Object
Dim tblPersonal As Object


Set curDatabase = CurrentDb
Set tblStore_Barcode = curDatabase.TableDefs("Store_Barcode")
Set tblPersonal = curDatabase.TableDefs("Personal")


If [Store_Barcode]![Barcode] = [Personal]![Barcode] Then
DoCmd.OpenForm (Personal_2)
Else
DoCmd.OpenForm (Personal)
End If
End Sub

I recieve the Run time error 13 - type mismatch

If [Store_Barcode]![Barcode] = [Personal]![Barcode] Then

This is the line that is highlighted. Any ideas why it is doing this?

Please check the data type of the fields 'Barcode' in both table, the Personal and the Store_Barcode. The data type of the two must be the same, example the Barcode in Personal is in Integer data type and the other is in "Text/Char" data type, then it would really return an Error.

The datatype is the same for both. I made sure of that before i attempted writing the code, and i have since checked it several times to be sure.

I believe the problem is with the actual syntax. However i dont know why it is doing this.

try to remove the bracket "[]"

If [Store_Barcode]![Barcode] = [Personal]![Barcode] Then

or try to look the value if it is DBNull. dbnull is not a string type in which if you will try to use it in comparison of strings it would throw an exception error...

This article has been dead for over six months. Start a new discussion instead.