A Microsoft Office (Excel, Word) forum. OfficeFrustration

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » OfficeFrustration forum » Microsoft Access » Setting Up & Running Reports
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

Filter Report Date in VBA



 
 
Thread Tools Display Modes
  #1  
Old April 1st, 2010, 11:17 PM posted to microsoft.public.access.reports
Jim
external usenet poster
 
Posts: 39
Default Filter Report Date in VBA

I have an Access 2003 report that I'm trying to filter in VBA. I have a form
setup with radio buttons for selecting year to date or everything. I have a
Select Case statement in the On Open event of the report, but I don't know
the correct syntax for the filter. Currently this is in the Filter section
of the report: Year([dtmDate]) = Year(Now()) and it works, but what is the
correct syntax forVBA and also to tell it to show all records for option 2?
Thanks

Jim


  #2  
Old April 1st, 2010, 11:52 PM posted to microsoft.public.access.reports
Marshall Barton
external usenet poster
 
Posts: 5,361
Default Filter Report Date in VBA

Jim wrote:
I have an Access 2003 report that I'm trying to filter in VBA. I have a form
setup with radio buttons for selecting year to date or everything. I have a
Select Case statement in the On Open event of the report, but I don't know
the correct syntax for the filter. Currently this is in the Filter section
of the report: Year([dtmDate]) = Year(Now()) and it works, but what is the
correct syntax forVBA and also to tell it to show all records for option 2?


You should use the OpenReport method's WhereCondition
argument to specify the filter. That way the report has no
need to be aware of what in on some form.

The code behind the form button that opens the report would
look something like:

Dim strWhere As String
If theoptiongroup = 1 Then
strWhere = "Year(dtmDate) = Year(Date())"
End If
DoCmd.OpenReport "the report", acViewPreview, , strWhere

--
Marsh
MVP [MS Access]
  #3  
Old April 5th, 2010, 05:27 AM posted to microsoft.public.access.reports
Armen Stein[_2_]
external usenet poster
 
Posts: 157
Default Filter Report Date in VBA

On Thu, 01 Apr 2010 16:52:39 -0600, Marshall Barton
wrote:

You should use the OpenReport method's WhereCondition
argument to specify the filter. That way the report has no
need to be aware of what in on some form.


Another way to have a report prompt the user for criteria before it
runs is to open a form from the report's Open event. Open the form in
Dialog mode so that the report waits for the form to be closed or
hidden before it proceeds. That way you can collect criteria from the
user and build a Where clause for the report. You can also do other
things like hiding and showing detail sections based on the user's
preference.

It also means that you can call the report directly - you don't need
to call it from a form. The benefit is that the selection form is
reusable - it can be called from multiple reports if they need the
same criteria.

I've posted examples of this technique on our free J Street Downloads
page at http://ow.ly/M58Y
See "Report Selection Techniques".

Armen Stein
Microsoft Access MVP
www.JStreetTech.com

 




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump


All times are GMT +1. The time now is 06:21 PM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 OfficeFrustration.
The comments are property of their posters.