
Embedding Wildcards in filter using VBA
Help...
I cannot seem to get a search string to operate properly. If I goto
filter by form, and type in *NC*, I will get all records containing the
two characters NC together somewhere in that field.
I need to change the 2 letters depending upon which state a user has
selected on the US map subform.
I have tried a number of options, but here is my code (that fails
miserably):
Dim strFilterStrg As String
Dim strPartialStrg As String
' I have seperated the filter string into 2 parts (after
' messing with 1 concatenation string unsuccessfully numerous '
times). WantsStates is the variable that I am trying to ' filter.
fnState is the state code variable received by my
' function.
' I want the want states variable to have *NC*. If it does,
' I receive all records with NC in it. If I use my code, I seem
' to either get a run time error, or only 1 blank record.
strPartialStrg = "Like *" & fnState & "*"
strFilterStrg = "WantsStates = " & strPartialStrg
. . .
Case "NC"
If (TypeCode = "Candidates") Then
Forms![Candidates].Filter = strFilterStrg
Else
Forms![zForms].RecordSource = "zmidatlantic hospitals"
Forms![zForms].Filter = "State = 'NC'"
End If
Thanks,
Lee