Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Problem with filter (VBA) 1

Status
Not open for further replies.

Walshie1987

Technical User
Oct 5, 2006
100
I have a search box (txtSearch) and a button (cmdSearch) when i enter text in txtSearch and click cmdSearch, the following code runs and filters my data to the criteria in txtSearch:

Me.Filter = ""
txtSearch.SetFocus
If Len(txtSearch.Text) = 0 Then Exit Sub

Dim strSearch As String
strSearch = "Like '*" & Me.txtSearch.Value & "*' "
Me.Filter = "tblUsers.LastName " & strSearch
Me.FilterOn = True

That is simple enough, but now, i want a message box to appear if no records match the criteria saying "No record found, add new record?" with the option of Yes nd No, I know how to make messages boxes, Yes No buttons and case select etc. But just not sure of the code i need to activate the box in the first place, any ideas?

I've had a play around with IF function but can't figyre it out.

No doubt someone out there can help.

Thanks alot
Chris
 
You can use the RecordCount property after you filter:

[tt]If Me.Recordset.RecordCount=0 Then
If msgbox ...[/tt]
 
Once again you have sorted it for me Remou, I knew it would be something simple, jsut not that simple :)

Thanks again
Chris
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top