Embedding Wildcards in filter using VBA 
Author Message
 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




Thu, 17 Feb 2000 03:00:00 GMT  
 Embedding Wildcards in filter using VBA

     strPartialStrg = "Like *" & fnState & "*"

Should be

     strPartialStrg = "Like '*" & fnState & "*'"

There is an extra single quote before the first asterisk and another one
after the second asterisk.



Quote:
> 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





Fri, 18 Feb 2000 03:00:00 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. Using CDO and the FILTER with wildcard

2. Recorset.Filter using wildcards against an Access DB

3. ADO recordset filter using wildcards - results in error 3001

4. Recorset.Filter using wildcards against an Access DB

5. Using WildCard (*) with .FileSearch.Filename in Access97 VBA with Windows 2000

6. Creating Embedded word documents from within Access using VBA

7. Using VBA to embed excel ranges and graphs in a mail item

8. Opening embedded Word Doc in Powerpoint Slideshow using VBA

9. Wildcard Filter

10. Does Filter use wildcards?

11. help!filtering data with wildcards!

12. Recordset.Filter property And Wildcards (?)

 

 
Powered by phpBB® Forum Software