Working with Filters

A

Afrosheen

Thanks for reading this post

I'm using a table with only four fields being used. I have an unbound text
box, search command button and a find next button. I'm using the unbound text
box {called: txtSearch}

When you enter the last name of a person it will create a filter for that
last name. That way if there are 4-5 last names the same it will filter them
all together.

Everytime I tried the code it keeps on prompting me for the last name. Then
it is supposed to go to that record in the filter so I can change
information. The trouble is that it doesn't work. After I've input the
information it will stop and tell me that the docmd are not available.

I also would like it to tell me when I'm at the end of the search.

Could you please check the code for me" Here it is.

Private Sub cmdSearch_Click()
Dim lNameRef, stwhere 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 lName

stwhere = "[lname] =" & txtSearch
Filter = stwhere
FilterOn = True
DoCmd.ShowAllRecords
DoCmd.GoToControl ("lname")
DoCmd.FindRecord Me!txtSearch

LName.SetFocus
lNameRef = LName.Text
txtSearch.SetFocus
strSearch = txtSearch.Text

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

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

Thanks
 

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

Similar Threads

Need help with this code 0
Search form help 3
Record Search within a Form 3
DoCmd.GoToControl "[MODEL]" 1
Seaching using text box 6
Optional Search 0
Access Form Validation 2
LIKE search help needed 3

Top