I have a search box on a form that opens another form (frmTraining) at the selected record (almost)
First Part - as the frmTraining loads with this code to go to a new record
Private Sub Form_Load()
If Not Me.NewRecord Then
RunCommand acCmdRecordsGoToNew
End If
Me.TrainDate.SetFocus
Me.LoggedOn = cboUser
End Sub
the code from the search box has a line to return to the previous record (the only record as they are filtered)
Private Sub btnTrainReport_Click()
'Message for No Search Entry
If IsNull(Me.SearchBoxTrainID) Or Me.SearchBoxTrainID = "" Then
MsgBox "You must enter or select a valid Incident Number", vbOKOnly, "Required Data"
Me.SearchBoxTrainID.SetFocus
Exit Sub
End If
Dim strWhere As String
If Not IsNull(Me.SearchBoxTrainID) Then
strWhere = "IDTraining = " & Me.SearchBoxTrainID
Exit Sub
End If
DoCmd.OpenForm "frmTraining", acNormal, , strWhere
'as frm opens to new record return to previous
RunCommand acCmdRecordsGoToPrevious
End Sub
So all that works but my question is that if a user enters a ID No. that does not exist
(why this would happen I don't know as SearchBoxTrainID is an unbound combo)
a runtime error occurs 2046 this command is not available RunCommand acCmdRecordsGoToPrevious
of course the form has opened at a blank record
So my question is should I be trying to handle that error or is there another solution to this
Thanks