D
dgodfrey
I have a search form in my database that searches for records, but it does
not behave the way I would like it to. I also need to make it more functional.
The user flow works like this:
The database opens to the switchboard, which has the following options: Add
a new record, edit an existing record, search for a record, exit databse.
Obviously, the search form is option 3 (search for a record) and when that is
clicked, the search form pops up and waits for input. If an invalid last name
is entered, it closes the main form and waits for another try. If correct, it
changes the current record in the main form. I do not want the user to ever
see the main form until either a valid name is found, or they choose to add a
new record and a blank form is displayed.
Here is the current search form code:
Option Compare Database
'--------------------------------------------------------------
'Graham Thorpe 25-01-02. Modified by Derek Godfrey 06-15-08
'--------------------------------------------------------------
Private Sub cmdSearch_Click()
Dim strNameSearch As String
Dim strSearch 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 strLastName
DoCmd.OpenForm "Bans", acNormal, , , acHidden
DoCmd.ShowAllRecords
DoCmd.GoToRecord , , acNewRec
DoCmd.GoToControl ("strLastName")
DoCmd.FindRecord Me!txtSearch
Forms!Bans!strLastName.SetFocus
strNameSearch = Forms!Bans!strLastName.Text
txtSearch.SetFocus
strSearch = txtSearch.Text
'If matching record found sets focus in strLastName and shows msgbox
'and clears search control
If strNameSearch = strSearch Then
MsgBox "Match Found For: " & strSearch, , "Congratulations!"
Forms!Bans!strLastName.SetFocus
txtSearch = ""
DoCmd.Close acForm, "Name Search"
Forms!Bans.SetFocus
'If value not found sets focus back to txtSearch and shows msgbox
Else
MsgBox "Match Not Found For: " & strSearch & " - Please Try
Again.", _
, "Invalid Search Criterion!"
txtSearch.SetFocus
DoCmd.Close acForm, "Bans"
End If
End Sub
What I am wanting it to do is allow me to search by last name, and go to
that record without displaying the main form at all (which it is currently
doing -showing the 1st record, then goes to the correct record if it is
found), if there is only one person with that last name. If there is more
than one record with that same last name, I need the user to be prompted to
input a first name, and if necessary after that a middle initial. If there is
more than one person with the same first, middle and last name I would like
the user to receive a list to choose from where they can manually choose by
birthdate or ID # or something (Ideally they would be able to see a photo of
each person beside their name to choose that way).
After the correct record has been found, I THEN want it to display the main
form with the correct record, but not before. If no matching record is
found, I would like the user to have the option to either search again or add
a new record.
I believe I would like the record, once found, to only be updated with new
information (in a text field or checkbox I select), rather than a user being
able to edit the entire record. Perhaps that piece needs to be addressed
later?
Thanks for any help anyone can offer.
not behave the way I would like it to. I also need to make it more functional.
The user flow works like this:
The database opens to the switchboard, which has the following options: Add
a new record, edit an existing record, search for a record, exit databse.
Obviously, the search form is option 3 (search for a record) and when that is
clicked, the search form pops up and waits for input. If an invalid last name
is entered, it closes the main form and waits for another try. If correct, it
changes the current record in the main form. I do not want the user to ever
see the main form until either a valid name is found, or they choose to add a
new record and a blank form is displayed.
Here is the current search form code:
Option Compare Database
'--------------------------------------------------------------
'Graham Thorpe 25-01-02. Modified by Derek Godfrey 06-15-08
'--------------------------------------------------------------
Private Sub cmdSearch_Click()
Dim strNameSearch As String
Dim strSearch 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 strLastName
DoCmd.OpenForm "Bans", acNormal, , , acHidden
DoCmd.ShowAllRecords
DoCmd.GoToRecord , , acNewRec
DoCmd.GoToControl ("strLastName")
DoCmd.FindRecord Me!txtSearch
Forms!Bans!strLastName.SetFocus
strNameSearch = Forms!Bans!strLastName.Text
txtSearch.SetFocus
strSearch = txtSearch.Text
'If matching record found sets focus in strLastName and shows msgbox
'and clears search control
If strNameSearch = strSearch Then
MsgBox "Match Found For: " & strSearch, , "Congratulations!"
Forms!Bans!strLastName.SetFocus
txtSearch = ""
DoCmd.Close acForm, "Name Search"
Forms!Bans.SetFocus
'If value not found sets focus back to txtSearch and shows msgbox
Else
MsgBox "Match Not Found For: " & strSearch & " - Please Try
Again.", _
, "Invalid Search Criterion!"
txtSearch.SetFocus
DoCmd.Close acForm, "Bans"
End If
End Sub
What I am wanting it to do is allow me to search by last name, and go to
that record without displaying the main form at all (which it is currently
doing -showing the 1st record, then goes to the correct record if it is
found), if there is only one person with that last name. If there is more
than one record with that same last name, I need the user to be prompted to
input a first name, and if necessary after that a middle initial. If there is
more than one person with the same first, middle and last name I would like
the user to receive a list to choose from where they can manually choose by
birthdate or ID # or something (Ideally they would be able to see a photo of
each person beside their name to choose that way).
After the correct record has been found, I THEN want it to display the main
form with the correct record, but not before. If no matching record is
found, I would like the user to have the option to either search again or add
a new record.
I believe I would like the record, once found, to only be updated with new
information (in a text field or checkbox I select), rather than a user being
able to edit the entire record. Perhaps that piece needs to be addressed
later?
Thanks for any help anyone can offer.