search by text box x2

H

harleyken

To All;
I am trying to code my form so some controls are hidden until a match is
found. One form searches by a single box, another gives the option to search
by either of two boxes...

I can get the forms to search (and find) the string typed into the unbound
text box, but if nothing is entered, all records are displayed. I would like
the focus to return to the 'search box' without displying all the records..
is this possible?

table structure - single table
self taught, please be patient with my ignorance!

here is code i tried for "form2" (text85 is the search box, [usps tracking
number] is what I want to search using a partial number to speed up the
search process..

Dim uspsref As String
Dim strsearch As String

If IsNull(Me![Text85]) Or (Me![Text85]) = "" Then
MsgBox "I'm confused, nothing to search for", vbOKOnly, "Give me
something!"
Me![Text85].SetFocus
Exit Sub
End If
DoCmd.ShowAllRecords
DoCmd.GoToControl ("[usps tracking number]")
DoCmd.FindRecord ("[usps tracking number] Like " & "'*" & Me![Text85]
& "*'")

[usps tracking number].SetFocus
uspsref = [usps tracking number].Text
Text85.SetFocus
strsearch = Text85.Text

If uspsref = strsearch Then
Me![Date USPS receipt Rec].Visible = True
Me.[Date USPS receipt Rec].SetFocus
Me![Text80].Visible = True
Me![Command94].Visible = True
Text85 = ""
Else
MsgBox "I cannot find anything matching " & strsearch & " - Please
try again."
Text85.SetFocus
End If
End Sub
+++++++++++++++

form 3
slightly different approach (showing both examples in hopes someone can tell
which is the best start! [text105] [text107])

Private Sub Text105_AfterUpdate()
Me![Text107] = ""
Me.[Date Results Rec].SetFocus
If IsNull(Me.Text105) Then
Me.FilterOn = False
Else
Me.Filter = "[LAST] Like " & "'*" & Me![Text105] & "*'"
Me.FilterOn = True
End If

End Sub

Private Sub Text107_AfterUpdate()
Me![Text105] = ""
Me.[Date Results Rec].SetFocus
If IsNull(Me.Text107) Then
Me.FilterOn = False
Else
Me.Filter = "[agency case no] Like " & "'*" & Me![Text107] & "*'"
Me.FilterOn = True
End If

End Sub
+++++++++++++++
I am presuming the * is what is returning all the records.. the US postal
service USPS tracking number is for registered mail and contains 5 series of
4 numbers stored as a text field (USPS Tracking Number: 0000 1111 2222 3333
4444)
 

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

Top