I have several forms based on queries which rely on user input to return relevant records. E.g. FrmInputLName requires the user to enter a lastname. FrmLastNames is then opened which displays the results, a query based on the name entered in the txtbox in FrmInputLName.
This is the code I use:
If IsNull(Me.txtInputLName) Then
MsgBox "Please enter a surname", vbOKOnly
Me.txtInputLName.SetFocus
Else
DoCmd.OpenForm "FrmLastNames"
DoCmd.Close acForm, "FrmInputLName"
DoCmd.Close acForm, "FrmMain"
DoCmd.Maximize
End If
The problem is, sometimes no records are returned by the query and the user faces a blank screen with no explanation. How can I get round this so the form only opens if there are records to display and if there aren't then a message displays showing that there are no matching records?
This is the code I use:
If IsNull(Me.txtInputLName) Then
MsgBox "Please enter a surname", vbOKOnly
Me.txtInputLName.SetFocus
Else
DoCmd.OpenForm "FrmLastNames"
DoCmd.Close acForm, "FrmInputLName"
DoCmd.Close acForm, "FrmMain"
DoCmd.Maximize
End If
The problem is, sometimes no records are returned by the query and the user faces a blank screen with no explanation. How can I get round this so the form only opens if there are records to display and if there aren't then a message displays showing that there are no matching records?