txt search box returns all records when wildcard is entered

T

Tom

I have used a simple textbox search originally created by Graham Thorpe
[Event Procedure]. When I open my search form If I type in and abbreviated
search text for example 206 vs. 206-030-987-101 It returns all of the records
in the database. If I search on 206-030-987-101 it will find that specific
record and display it, but all records are available.

I would like help with using the textbox search to bring up only those
records containing the exact match if one is available and not physically
being able to view any other records in the current form.

I would like to also be able to perform a wildcard search that would bring
up all records with the first three digits as 206, but only those records in
the form view and not again being able to see all of the records in the
database in that search form.

I can forward examples if necessary for understanding.
 
R

Ron2006

What is the code you are using in the criteria for the query?

We need some more specifics.
 
T

Tom

This is an event proecedure attached to a command button in the header of my
form.

Private Sub PNsearch_Click()
Dim PartnumberRef As String
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 Partnumber

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

Partnumber.SetFocus
PartnumberRef = Partnumber.Text
txtSearch.SetFocus
strSearch = txtSearch.Text

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

If strPartnumberRef = strPartnumber Then
MsgBox "Match Found For: " & strSearch, , "Congratulations!"
Partnumber.SetFocus
txtSearch = ""

'If value not found sets focus back to txtSearch and shows msgbox
Else
MsgBox "Match Not Found Fro: " & strSearch & " - Please Try
Again.", _
, "Invalid Search Criterion!"
txtSearch.SetFocus

End If
End Sub
 
R

Ron2006

Tom, I simply have NOT used find much at all, so I don't have any
real suggestion how to modify that code.

An alternative if noone else offers a more specific solution would be
to use a query with the criteria set to
Like txtSearch & "*" and a requery of the query in the onclick event
of the button. It would return all those that are close but be an
empty subform if there were none that matched.

My gut feel is that the action you are seeing as you have it set up is
the expected action on a find that does NOT find any record.

Ron
 
Top