search functionality

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi,

I have created a form to perfom data entry and modification. The current
scenario is, user has to go through all the data to find the record they
intend to edit.

However, I am looking for a functionality, where the user can enter search
string in a text box which will bring up the record(s) containg the results
and the user can then modify (do the data entry) .

Any advice will be much appreciated.

thanks

dhaval
 
Dhaval said:
Hi,

I have created a form to perfom data entry and modification. The current
scenario is, user has to go through all the data to find the record they
intend to edit.

However, I am looking for a functionality, where the user can enter search
string in a text box which will bring up the record(s) containg the results
and the user can then modify (do the data entry) .

Any advice will be much appreciated.

thanks

dhaval

Hi,

If you are searching on one particular field then you can use the
following code...

Private Sub cmdSearch_Click()
Dim strStudentRef 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 strStudentID

DoCmd.ShowAllRecords
DoCmd.GoToControl ("strStudentID")
DoCmd.FindRecord Me!txtSearch

strStudentID.SetFocus
strStudentRef = strStudentID.Text
txtSearch.SetFocus
strSearch = txtSearch.Text

'If matching record found sets focus in strStudentID and shows msgbox
'and clears search control

If strStudentRef = strSearch Then
MsgBox "Match Found For: " & strSearch, , "Congratulations!"
strStudentID.SetFocus
txtSearch = ""

'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
End If
End Sub


This code is looking up a Student ID field in a database containing
student records, addresses, contact details etc.

It assumes that you have created a text box (txtSearch) and a command
button (cmdSearch).

Whatever you create, just jig about with the names in the code so that
they match the names of your text box/command button and it should work
fine!

Cheers

J
 
Here's a few choices.

Option 1: Select the record by choosing a unique value in a combo box:
Using a Combo Box to Find Records
at:
http://allenbrowne.com/ser-03.html

Option 2: Choose which field to filter on, and enter a value. The form
filters with each keystroke:
Find as you type
at:
http://allenbrowne.com/AppFindAsUType.html

Option 3: Build a search form with several search boxes where the user can
enter any combination of criteria and find matches:
Search form - Handle many optional criteria
at:
http://allenbrowne.com/ser-62.html
 
Back
Top