A family of Microsoft relational database management systems designed for ease of use.
I would test whether there are matching records in the On Click event procedure of the command button on form(1) that you use to open form(2).
Let's say:
- The text box is named txtSearch.
- The command button is named cmdOpenForm2.
- The client table is named tblClient.
- The field you search on is named Surname.
- The name of form(2) is frmClient.
The code could look like this:
Private Sub cmdOpenClientForm_Click()
Dim strWhere As String
' Assemble where-condition from text box
strWhere = "[Surname] Like" & Chr(34) & Me.[txtSearch] & Chr(34)
' Check if there are matches
If DCount("*", "[tblClient]", strWhere) = 0 Then
' If not, select the search box
Me.[txtSearch].SetFocus
' Display a message
MsgBox "There are no clients matching the criteria that you entered!", vbExclamation
' And get out
Exit Sub
End If
' If we get here, there are matches
' So we can open the client form
DoCmd.OpenForm FormName:="frmClient", WhereCondition:=strWhere
End Sub