Hi All,
I have a control on my form that looks up a value in a linked table. The goal was to ensure that a product part number was scanned in at the previous station before proceeding. Right now, it does that but if the part number is not located/keyed in wrong, it still saves the record. I would like to re-select the control (CathodeID) in the event that the part number is not found. I have the below code. Any help is much appreciated.
Thanks in advance!,
Audra
I have a control on my form that looks up a value in a linked table. The goal was to ensure that a product part number was scanned in at the previous station before proceeding. Right now, it does that but if the part number is not located/keyed in wrong, it still saves the record. I would like to re-select the control (CathodeID) in the event that the part number is not found. I have the below code. Any help is much appreciated.
Code:
Private Sub CathodeID_LostFocus()
Dim myCartridgeID As String
myCartridgeID = Me.CathodeID.Text
If Len(Trim(myCartridgeID)) > 0 Then
Dim db As DAO.Database
Dim myRecordSet As DAO.Recordset
Dim MySQL As String
'Open connection to current Access database
Set db = CurrentDb()
'Create SQL statement to retrieve value from GST table
MySQL = "select * From [PottingIn] Where [CathodeIDIn] = " & """" & Me.CathodeID.Text & """"
Set myRecordSet = db.OpenRecordset(MySQL)
'Retrieve value if data is found
If myRecordSet.EOF = False Then
'do nothing
Else
MsgBox ("This Cathode was not Potted In!")
End If
myRecordSet.Close
Set myRecordSet = Nothing
End If
End Sub
Audra