By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,880 Members | 2,443 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,880 IT Pros & Developers. It's quick & easy.

Filter a report

P: n/a
I'm trying to filter a report with a date in VB code.

If I type an actual date bracketed with the pound symbol (i.e. #3-Jul-08#)
I can get the filter to work. I can't seem to get it to work by using a
variable. Am I trying to do the impossible?

I've tried using a date variable that I know contains a valid date. I've
tried bracketing it with pound symbols, single quotations etc. I've tried a
string variable and used the 'CDate' function. I've tried many, many, many
variations and just can't seem to place a date within a filter without
typing it in explicitly.

ex: report.filter = "[This date field] DateVariable"
report.FilterOn = True

Thanks,

Gord
Sep 17 '08 #1
Share this Question
Share on Google+
3 Replies


P: n/a
"Gord" <x1******@telus.netwrote in message
news:Zl%zk.229$T65.175@edtnps82...
I'm trying to filter a report with a date in VB code.

If I type an actual date bracketed with the pound symbol (i.e.
#3-Jul-08#) I can get the filter to work. I can't seem to get it to work
by using a variable. Am I trying to do the impossible?

I've tried using a date variable that I know contains a valid date. I've
tried bracketing it with pound symbols, single quotations etc. I've tried
a string variable and used the 'CDate' function. I've tried many, many,
many variations and just can't seem to place a date within a filter
without typing it in explicitly.

ex: report.filter = "[This date field] DateVariable"
report.FilterOn = True

Thanks,

Gord
Try:
report.filter = "[This date field] #" & DateVariable & "#"
Fred Zuckerman
Sep 17 '08 #2

P: n/a
On Wed, 17 Sep 2008 04:05:13 GMT, "Gord" <x1******@telus.netwrote:

If I understand you correctly, you'd want to:
* Create a public function in a standard module that returns your
variable:
Public Function GetDateVariable() as Date
GetDateVariable = g_MyDateVariable
End Function
* Call that function from your query or filter:
report.filter = "[This date field] GetDateVariable()

-Tom.
Microsoft Access MVP

>I'm trying to filter a report with a date in VB code.

If I type an actual date bracketed with the pound symbol (i.e. #3-Jul-08#)
I can get the filter to work. I can't seem to get it to work by using a
variable. Am I trying to do the impossible?

I've tried using a date variable that I know contains a valid date. I've
tried bracketing it with pound symbols, single quotations etc. I've tried a
string variable and used the 'CDate' function. I've tried many, many, many
variations and just can't seem to place a date within a filter without
typing it in explicitly.

ex: report.filter = "[This date field] DateVariable"
report.FilterOn = True

Thanks,

Gord
Sep 17 '08 #3

P: n/a
Thanks Fred.

I had tried some variations like that but never kept the pound symbol within
the quotations and the variable outside. Takes a little getting used to.

Works fine.

Gord
"Fred Zuckerman" <Zu********@sbcglobal.netwrote in message
news:2O***************@nlpi068.nbdc.sbc.com...
"Gord" <x1******@telus.netwrote in message
news:Zl%zk.229$T65.175@edtnps82...
>I'm trying to filter a report with a date in VB code.

If I type an actual date bracketed with the pound symbol (i.e.
#3-Jul-08#) I can get the filter to work. I can't seem to get it to work
by using a variable. Am I trying to do the impossible?

I've tried using a date variable that I know contains a valid date. I've
tried bracketing it with pound symbols, single quotations etc. I've
tried a string variable and used the 'CDate' function. I've tried many,
many, many variations and just can't seem to place a date within a filter
without typing it in explicitly.

ex: report.filter = "[This date field] DateVariable"
report.FilterOn = True

Thanks,

Gord
Try:
report.filter = "[This date field] #" & DateVariable & "#"
Fred Zuckerman


Sep 17 '08 #4

This discussion thread is closed

Replies have been disabled for this discussion.