VBA help

gbanks

Registered User.
Local time
Today, 06:17
Joined
Feb 9, 2000
Messages
161
I use the code below on a search form to filter my table for data. The code works pretty well but it has one bug. The text box on my form that captures when the event occurred has 3 types Pre-Admin, Admin and Post-Admin. The problem is whe the user selects one of these types from the dropdown on the search form all the types show because the string below is using the Like statement and * to filter. So eveything shows. Is there a way to modify the lines below to only show exactly what is selected on the search form? So if the user selects Pre-Admin only Pre-admin records will show. Thanks..

If Not IsNull(Me.txtOccurring) Then
strWhere = strWhere & " (SiteIssues_tbl.Occurring) Like '*" & Me.txtOccurring & "*' AND"
End If
 
I use the code below on a search form to filter my table for data. The code works pretty well but it has one bug. The text box on my form that captures when the event occurred has 3 types Pre-Admin, Admin and Post-Admin. The problem is whe the user selects one of these types from the dropdown on the search form all the types show because the string below is using the Like statement and * to filter. So eveything shows. Is there a way to modify the lines below to only show exactly what is selected on the search form? So if the user selects Pre-Admin only Pre-admin records will show. Thanks..

If Not IsNull(Me.txtOccurring) Then
strWhere = strWhere & " (SiteIssues_tbl.Occurring) Like '*" & Me.txtOccurring & "*' AND"
End If


Given your code everything should show only if the user is selecting "Admin" The other two should filter out everthing that does not contain either "Pre-Admin" or "Post-Admin", depending on the user selection. Are you really wanting to do a like filter or do you really want to filter so only those exactly matching show? Are you searching in a field that has more than the values in the drop down? Ie. does the field have text surrounding the "Pre-Admin", something like "When the patient was checked in the Pre-Admin area....". In that case I would use a like filter but if it is just the choice of the three then I would use an = filter. Even witht he AND phrase if you are filter on "Pre-Admin" AND "Post-Admin" the = would still work.
 
Take out the wildcards.
 

Users who are viewing this thread

Back
Top Bottom