How to create a Search Feature

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

Guest

Ive read a few posts that cover this but I wanted to ask a simple way of
creating a search form or seach feature that will allow users to type in for
example, first name, last name or zip code to locate and display records in a
form view that match the criteria.

The database I'm using is quite simple, contains a customer and complaints
table only. The complaints table is a sub form within the cutomer form. I
want to ceate a search form to avoid creating duplicate customer records.

Thanks.

Wasim
 
Ive tried the code recommended below but keep receiving a debug error. My
code is:

Private Sub Command16_Click()

Dim strPostcode 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 strPostcode

DoCmd.ShowAllRecords
DoCmd.GoToControl (strPostcode) - DEBUGS HERE
DoCmd.FindRecord Me!Txtsearch

Postcode.SetFocus
strPostcode = Postcode.Text
Txtsearch.SetFocus
strSearch = Txtsearch.Text

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

If strPostcode = strSearch Then
MsgBox "Match Found For: " & strSearch, , "Congratulations!"
Postcode.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
 
What is the strPostcode?
You didn't assign a name of a field to go to

strPostcode = "Insert here the field Name in form"

Or
DoCmd.GoToControl ("FieldName InForm")


--
\\// Live Long and Prosper \\//
BS"D


FerrariWA said:
Ive tried the code recommended below but keep receiving a debug error. My
code is:

Private Sub Command16_Click()

Dim strPostcode 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 strPostcode

DoCmd.ShowAllRecords
DoCmd.GoToControl (strPostcode) - DEBUGS HERE
DoCmd.FindRecord Me!Txtsearch

Postcode.SetFocus
strPostcode = Postcode.Text
Txtsearch.SetFocus
strSearch = Txtsearch.Text

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

If strPostcode = strSearch Then
MsgBox "Match Found For: " & strSearch, , "Congratulations!"
Postcode.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

Ofer said:
Check this link on how to create a search form, with a sample to download

http://www.databasedev.co.uk/text_search.html
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top