So I am trying to do a few things to a text box and I can't quite get it to do what I want.
I want it to:
1. Check to see if the what the user input into the text box is a record. (It does this currently)
2. If the user types in something that is not a record and moves from the textbox a popup comes up and the user has to type in a valid string.
This is the code:
Code:
Private Sub Upstream_AfterUpdate()
Dim rst As DAO.Recordset
Set rst = CurrentDb.OpenRecordset("Devices", dbOpenDynaset)
'Check to make sure Upstream Device is in Devices Table
With rst
.FindFirst ("[Device ID]='" & Upstream.Text & "'")
If .NoMatch And Len(Upstream.Text) > 0 Then
MsgBox "Not a valid Upstream Device"
'Set cursor back to Upstream textbox
Me.Upstream.SetFocus
Me.Upstream.SelStart = Nz(Len(Me.Upstream), 0)
Else
'Do Nothing
End If
End With
End Sub
It correctly searches the proper column for the record and displays a pop up when it is incorrect but it does not keep the cursor in the textbox until the user inputs a valid string.
Any ideas as to why this code isn't working?