Could someone help me with this code please, i am trying to do a search from three tables using a form with a comand button called search and a text box, upon entering a value to search on the result should appear on the main form. This is my attempt below:
[Dim Organisation As Object
Dim Projects As Object
Dim Provision As Object
Dim Search As String
'Check txtSearch for Null value or Nill Entry first.
If IsNull(Me![txtSearch]) Or (Me![txtSearch]) = "" Then
MsgBox "Please enter a value!", vbOKOnly, "Invalid Search Criterion!"
Me![txtSearch].SetFocus
Exit Sub
End If
'Performs the search using value entered into txtSearch
'and evaluates this against values in any of the three tables,
DoCmd.ShowAllRecords
DoCmd.GoToRecord ("OrganisationID"
DoCmd.FindRecord Me!txtSearch
Organisation.SetFocus
Projects.SetFocus
Provision.SetFocus
'Organisation = Organisation
'Projects = Projects
'Provision = Provision
txtSearch.SetFocus
Search = txtSearch.Text
'If matching record found sets focus in any table
'and shows msgbox and clears search control
If Organisation Or Project Or Provision = Search Then
MsgBox "Match Found For: " & Search, , "Result!"
Organisation.SetFocus
Projects.SetFocus
Provision.SetFocus
txtSearch = ""
'If value not found sets focus back to txtSearch and shows msgbox
Else
MsgBox "Match Not Found For: " & Search & " - Please Try Again.", _
, "Invalid Search Criterion!"
txtSearch.SetFocus
End If
End Sub]
[Dim Organisation As Object
Dim Projects As Object
Dim Provision As Object
Dim Search As String
'Check txtSearch for Null value or Nill Entry first.
If IsNull(Me![txtSearch]) Or (Me![txtSearch]) = "" Then
MsgBox "Please enter a value!", vbOKOnly, "Invalid Search Criterion!"
Me![txtSearch].SetFocus
Exit Sub
End If
'Performs the search using value entered into txtSearch
'and evaluates this against values in any of the three tables,
DoCmd.ShowAllRecords
DoCmd.GoToRecord ("OrganisationID"
DoCmd.FindRecord Me!txtSearch
Organisation.SetFocus
Projects.SetFocus
Provision.SetFocus
'Organisation = Organisation
'Projects = Projects
'Provision = Provision
txtSearch.SetFocus
Search = txtSearch.Text
'If matching record found sets focus in any table
'and shows msgbox and clears search control
If Organisation Or Project Or Provision = Search Then
MsgBox "Match Found For: " & Search, , "Result!"
Organisation.SetFocus
Projects.SetFocus
Provision.SetFocus
txtSearch = ""
'If value not found sets focus back to txtSearch and shows msgbox
Else
MsgBox "Match Not Found For: " & Search & " - Please Try Again.", _
, "Invalid Search Criterion!"
txtSearch.SetFocus
End If
End Sub]