I have a simple form that returns a product's description and cost based on a barcode being scanned.
This for works fine when the barcode exists in the Inventory table but if the barcode doesn't exit the code is supposed to run an error trap that displays a message box.
Currently it just jumps down to the next line. The rsEnq.NoMatch doesn't seem to be catching the 'NoMatch'
Code below. Any help greatly appreciated.
Dim mydb As Database, rsEnq As Recordset
Dim sqlBarCode As String
sqlBarCode = "SELECT DISTINCTROW tblInventory.BarCode, tblInventory.Description, tblInventory.SalePrice "
sqlBarCode = sqlBarCode & "FROM tblInventory "
sqlBarCode = sqlBarCode & "WHERE (tblInventory.BarCode ='" & Me.txtBarCode1.Text & "');"
' Create database.
Set mydb = DBEngine.Workspaces(0).Databases(0)
' Create dynaset.
Set rsEnq = mydb.OpenRecordset(sqlBarCode, DB_OPEN_SNAPSHOT)
If rsEnq.NoMatch Then
MsgBox ("BarCode was not recognised. Please write down your Name and the product taken in the book provided."), 0 + 64, "Error"
' Populate text box controls.
On Error Resume Next
Me![txtDesc1].Value = rsEnq.Fields("[Description]").Value
Me![txtCost1].Value = rsEnq.Fields("[SalePrice]").Value
Me.txtBarCode2.Locked = False