Why doesn't this work? 
Author Message
 Why doesn't this work?

I am trying to apply a filter to a form programmatically. According to the
online help, I can use a string expression to set the criteria for the WHERE
clause of the filter property.

The example they use in the online help is:
    Me.Filter = "Country = 'USA'"

I want the criteria to vary depending on what the user types into a textbox
on the form so I added the following code to the textbox:

Private Sub txtEventFilter_AfterUpdate()
    Dim str As String
    str = Me![txtEventFilter]

    MsgBox str

    Me.Filter = "EventID = str"
    Me.FilterOn = True
End Sub

After I update the textbox, it prompts me for the "str" parameter.  Why is
this?  I  supply it, the filter works fine.  But why doesn't it just accept
the "str" value automatically without prompting?  The MsgBox function
displays the "str" value just fine.

Any thoughts would be appreciated.

Dave
--------
David R. Frick & Co., CPA
http://www.*-*-*.com/




Tue, 26 Dec 2000 03:00:00 GMT  
 Why doesn't this work?
You have the str enclosed in the quotes.  Remove this and concatenate it and
it should be fine.

Me.Filter = "EventID = " & str
Me.FilterOn = True

--
-- Tim Bloomer :)

Quote:

>I am trying to apply a filter to a form programmatically. According to the
>online help, I can use a string expression to set the criteria for the
WHERE
>clause of the filter property.

>The example they use in the online help is:
>    Me.Filter = "Country = 'USA'"

>I want the criteria to vary depending on what the user types into a textbox
>on the form so I added the following code to the textbox:

>Private Sub txtEventFilter_AfterUpdate()
>    Dim str As String
>    str = Me![txtEventFilter]

>    MsgBox str

>    Me.Filter = "EventID = str"
>    Me.FilterOn = True
>End Sub

>After I update the textbox, it prompts me for the "str" parameter.  Why is
>this?  I  supply it, the filter works fine.  But why doesn't it just accept
>the "str" value automatically without prompting?  The MsgBox function
>displays the "str" value just fine.

>Any thoughts would be appreciated.

>Dave
>--------
>David R. Frick & Co., CPA
>http://www.frick-cpa.com





Wed, 27 Dec 2000 03:00:00 GMT  
 Why doesn't this work?
No problem, sometime the extra set of eyes helps.

--
Tim Bloomer :)


:Thanks so much Tim, that did the trick.
:
:Dave
:
:
:



Wed, 27 Dec 2000 03:00:00 GMT  
 Why doesn't this work?


Quote:
>You have the str enclosed in the quotes.  Remove this and concatenate it and
>it should be fine.

>Me.Filter = "EventID = " & str
>Me.FilterOn = True

This will work iff EventID is a numeric value -- you may want to check
something like,

 If Not IsNumeric(txtEventFilter) Then
   ' some kind of error handling
   Cancel = True
 End If

... in the BeforeUpdate event. If it were a text value, then you'd
have to quote it for the sake of the SQL handler:

 Me.Filter = "EventID = " & Chr$(34) & str & Chr$(34)

etc.

--



Thu, 28 Dec 2000 03:00:00 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. Why oh why doesn't this work?

2. Why doesn't this work???

3. Why doesn't this work?!!

4. Why doesn't this work?

5. why doesn't it work?????

6. Why doesn't this work?

7. Why doesn't this work anymore?

8. threading and why doesn't it work!!!! :)

9. Itemop.Navigate - Why doesn't it work?!

10. Why doesn't this work

11. Why doesn't it work?

12. Help needed !! Why doesn't this work

 

 
Powered by phpBB® Forum Software