Re: Search Feature

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



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






.



Relevant Pages

  • Re: Search Feature
    ... Dim Unit_IDRef As String ... Dim strSearch As String ... 'Check txtSearch for Null value or Nill Entry first. ... MsgBox "Please enter a value!", vbOKOnly, "Invalid Search ...
    (microsoft.public.access.forms)
  • Re: Error in text search facility code
    ... > 'Check txtSearch for Null value or Nill Entry first. ... > Exit Sub ... > 'If matching record found sets focus in strStudentID and shows msgbox ...
    (microsoft.public.access.forms)
  • Re: isnumeric compile error...
    ... A97 complains of a compile error. ... MsgBox "Numeric" ... I entered 1.2.2 and I got "Alpha". ... immedicate window. ...
    (comp.databases.ms-access)
  • Re: ADO -DAO problem?
    ... example MsgBox.Name) will return public_banker 'cause ... public_banker is the first field in your data collection and the index begin ... I have again a compile error: invalid use of property on ...
    (microsoft.public.access.modulesdaovba)
  • Subform search
    ... >Dim strSampleRef As String ... >Dim strSearch As String ... >'Check txtSearch for Null value or Null Entry first. ...
    (microsoft.public.access.forms)