Solved Search from form in another form

FahadTiger

Member
Local time
Today, 04:43
Joined
Jun 20, 2021
Messages
120
Hi all experts..
I found this file on one of the respected sites..and when I enter a value in the search box, it shows me the records..and it works fine..
I tried to create another form that has a text box to search in that form..I tried a lot, but it shows me an error..any advice, I am completely confused
 

Attachments

Why not just show the code?
You do not even say what the error is? :(
 
Code:
Private Sub Command2_Click()
Dim rst As Recordset
Dim strSearch As String

strSearch = Nz(Me.txtFindNo, "NA")

If Not IsNumeric(strSearch) Then
  MsgBox "Must Provide a valid Country ID"
Else
    If Not CurrentProject.AllForms("frmCountries").IsLoaded Then
      DoCmd.OpenForm "frmCountries"
    End If
    Set rst = Forms!frmCountries.Recordset
    rst.FindFirst "CountrySN = " & strSearch
    If rst.NoMatch Then MsgBox "No country ID matches " & strSearch
End If
End Sub

The above works, but I would think a user would search by name. Why would they know the number they are looking for? So you would have a combobox instead of a textbox with all the names. Then using autocomplete if a user is looking for Haiti and types "H" it would bring up Haiti. Even if they are searching by number, I would use a combobox limited to list not a textbox.
 
Last edited:
I found the solution... Thank you guys
Actually I was searching for records in one form through another form
 
Now I read your post...how amazing you are...much better than what I came up with..its perfect
Code:
Private Sub Command2_Click()
Dim rst As Recordset
Dim strSearch As String

strSearch = Nz(Me.txtFindNo, "NA")

If Not IsNumeric(strSearch) Then
  MsgBox "Must Provide a valid Country ID"
Else
    If Not CurrentProject.AllForms("frmCountries").IsLoaded Then
      DoCmd.OpenForm "frmCountries"
    End If
    Set rst = Forms!frmCountries.Recordset
    rst.FindFirst "CountrySN = " & strSearch
    If rst.NoMatch Then MsgBox "No country ID matches " & strSearch
End If
End Sub

The above works, but I would think a user would search by name. Why would they know the number they are looking for? So you would have a combobox instead of a textbox with all the names. Then using autocomplete if a user is looking for Haiti and types "H" it would bring up Haiti. Even if they are searching by number, I would use a combobox limited to list not a textbox.
 

Users who are viewing this thread

Back
Top Bottom