Re: Search Feature
- From: Klatuu <Klatuu@xxxxxxxxxxxxxxxxxxxxxxxxx>
- Date: Thu, 8 May 2008 11:40:04 -0700
Where in my code did you get a compile error. It was, of course, air code
written in the message editor, but from practical experience.
I don't understand what you mean about continuing the search. In most
cases, you either find a record or you don't. Perhaps if you could describe
what you are trying to accomplish and post all the existing code, we can
offer a how to.
--
Dave Hargis, Microsoft Access MVP
"Rohn" wrote:
Dave,.
I tried both approaches without success. When I removed
"Me![txtSearch].SetFocus" from the current code, no noticable difference?
When I replaced the code it gives me a VB Compile Error: Syntax Error
Did I do something wrong?
more information:
Previously, I had been trying to modify the last section of this Code
because it seem like everything works OK until, you do not find an existing
record and you want to continue to search. But the form & subform get
populated with the first record in the db while attempting your second
search in the search field.
"Klatuu" <Klatuu@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:A9113685-A81E-438F-8327-0AE3986C3D41@xxxxxxxxxxxxxxxx
All you need to do is remove this line of code:
Me![txtSearch].SetFocus
I would write it a little differently:
Private Sub cmdSearch_Click()
Dim Unit_IDRef As String
Dim strSearch As String
'Check txtSearch for Null value or Nill Entry first.
If Nz(Me.txtSearch, vbNullstring) = vbNullString Then
MsgBox "Please enter a value!", vbOKOnly, "Invalid Search
Criterion!"
Exit Sub
End If
--
Dave Hargis, Microsoft Access MVP
"Rohn" wrote:
Thanks Dave,
Here is the "On Click" event:
'--------------------------------------------------------------
'Seach field concept by Graham Thorpe
'--------------------------------------------------------------
Private Sub cmdSearch_Click()
Dim Unit_IDRef 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 UNIT_ID field
DoCmd.ShowAllRecords
DoCmd.GoToControl ("Unit_ID")
DoCmd.FindRecord Me!txtSearch
Unit_ID.SetFocus
Unit_IDRef = Unit_ID.Text
txtSearch.SetFocus
strSearch = txtSearch.Text
'If matching record found sets focus in UNIT_ID and shows msgbox
'and clears search control
If Unit_IDRef = strSearch Then
MsgBox "Match Found For: " & strSearch, , "Congratulations!"
Unit_ID.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
- Follow-Ups:
- Re: Search Feature
- From: Rohn
- Re: Search Feature
- From: Rohn
- Re: Search Feature
- References:
- Search Feature
- From: Rohn
- RE: Search Feature
- From: Klatuu
- Re: Search Feature
- From: Rohn
- Re: Search Feature
- From: Klatuu
- Re: Search Feature
- From: Rohn
- Search Feature
- Prev by Date: Re: Files launched w/ FollowHyperlink open but not visible
- Next by Date: Access Error Field cannot be updated. (Error 3164)
- Previous by thread: Re: Search Feature
- Next by thread: Re: Search Feature
- Index(es):
Relevant Pages
|