Hello all
I am trying to create a search form. I have a table called tblContact which has the field for postcodes in it. I have another table called tblSales which i have created a query to link the tblContacts to. On the frmSales the Postcode is a combo box. I am using the code below to search for the postcodes. I can't get it to find a postcode via the combo box. Sorry if i am not being very clear as my coding is very basic. Please help, thanks.
Private Sub btnSearch_Click ()
Dim strSearch As String
If IsNull(Me![PostcodeSearch]) Or (Me![PostcodeSearch]) = "" Then
MsgBox "You Must Enter A Postcode!", vbOKOnly, "Invalid Search!"
Me![PostcodeSearch].SetFocus
Exit Sub
End If
DoCmd.ShowAllRe cords
DoCmd.GoToContr ol ("Postcode")
DoCmd.FindRecor d Me!PostcodeSear ch
Postcode.SetFoc us
strPostcodeRef = Postcode.Text
PostcodeSearch. SetFocus
strSearch = PostcodeSearch. Text
If strPostcodeRef = strSearch Then
MsgBox "Match Found For: " & strSearch, , "Match Found!"
Postcode.SetFoc us
PostcodeSearch = ""
Else
MsgBox "No Match For: " & strSearch & " - Please Try Again.", _
, "No Match Found!"
PostcodeSearch. SetFocus
End If
End Sub
I am trying to create a search form. I have a table called tblContact which has the field for postcodes in it. I have another table called tblSales which i have created a query to link the tblContacts to. On the frmSales the Postcode is a combo box. I am using the code below to search for the postcodes. I can't get it to find a postcode via the combo box. Sorry if i am not being very clear as my coding is very basic. Please help, thanks.
Private Sub btnSearch_Click ()
Dim strSearch As String
If IsNull(Me![PostcodeSearch]) Or (Me![PostcodeSearch]) = "" Then
MsgBox "You Must Enter A Postcode!", vbOKOnly, "Invalid Search!"
Me![PostcodeSearch].SetFocus
Exit Sub
End If
DoCmd.ShowAllRe cords
DoCmd.GoToContr ol ("Postcode")
DoCmd.FindRecor d Me!PostcodeSear ch
Postcode.SetFoc us
strPostcodeRef = Postcode.Text
PostcodeSearch. SetFocus
strSearch = PostcodeSearch. Text
If strPostcodeRef = strSearch Then
MsgBox "Match Found For: " & strSearch, , "Match Found!"
Postcode.SetFoc us
PostcodeSearch = ""
Else
MsgBox "No Match For: " & strSearch & " - Please Try Again.", _
, "No Match Found!"
PostcodeSearch. SetFocus
End If
End Sub
Comment