Search Help

F

Froto

I have the following code behind the onclick event of a
button

Private Sub cbodate_Click()
Dim strdate As String
Dim strSearch As String
'Check for value in date box

If IsNull(Me![txtdate]) Or (Me![txtdate]) = "" Then
MsgBox "Please enter a Date for your search!",
vbOKOnly, "Invalid Search Criterion!"
Me![txtdate].SetFocus
Exit Sub
End If
'---------------------------------------------------------
---------------------------

'Perform the search from the set value in txtdate
DoCmd.ShowAllRecords
DoCmd.GoToControl ("Date")
DoCmd.FindRecord Me!txtdate

Date.SetFocus
strdate = Date
txtdate.SetFocus
strSearch = txtdate

'If matching record found show MsgBox and clear Control

If strdate = strSearch Then
MsgBox "Records found matching your Search:" &
strSearch, , "Valid Search!"
Date.SetFocus
txtdate = ""

'If values not found sets focus back to search box and
shows message

Else
MsgBox "No Records found matching your date selection:" &
strSearch & "Please Try Again.", , "Invalid Search
Criterion!"
txtdate.SetFocus
End If
End Sub

What's happening is the search is showing all records,
and not only the ones from the text box value, what do i
need to change to make this work

Thank you
 
N

Nikos Yannacopoulos

Froto,

It;s only doing what you asked it to do! You said "find me a record", not
filter!
To do what you seem to want (assuming you're doing this on a form), try the
ApplyFilter command (look it up inVBA help, it's pretty easy) or redefine
the recordsource property using your date control value in the WHERE clause.

HTH,
Nikos
 

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