Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Microsoft Office > Access and Access VBA > Access VBA
Password Reminder
Register
| FAQ | Members List | Search | Today's Posts | Mark Forums Read
Access VBA Discuss using VBA for Access programming.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Access VBA section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old January 19th, 2008, 02:05 PM
Registered User
Points: 30, Level: 1
Points: 30, Level: 1 Points: 30, Level: 1 Points: 30, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Sep 2007
Location: , , .
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Default Problem with DoCmd.Printout (Access2003)

I have a situation where I need to print a selected page from a report.

I use DoCmd.OpenReport ReportName, acDesignView, , WhereClause
followed by DoCmd.PrintOut acPages, pagenum, pagenum

PrintOut fails to apply the filter WhereClause, and all records from the table are included in the report. The correct page is printed, but from a report containing all records instead of only the selected ones. Is there any way around this?

Note that if I print or preview the entire report, by using DoCmd.OpenReport ReportName, acViewNormal, , WhereClause
or DoCmd.OpenReport ReportName, acViewPreview, , WhereClause
the WhereClause filter is applied correctly.

Thanks,
  John
Reply With Quote
  #2 (permalink)  
Old January 22nd, 2008, 08:47 AM
Friend of Wrox
Points: 9,611, Level: 42
Points: 9,611, Level: 42 Points: 9,611, Level: 42 Points: 9,611, Level: 42
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Mar 2004
Location: Washington, DC, USA.
Posts: 3,069
Thanks: 0
Thanked 10 Times in 10 Posts
Default

This is an interesting problem. Normally I would use acNormal and this would print the report with the WHERE clause that I needed.

How is it that the report always has the same number of pages, and you always want the one page (or more) from the same location? If the data is dynamic, then the page numbers will float as the data changes. If the report is static or an aggregate, why not create a report that just has the pages you want in it, and then print that report, instead of creating a report that has more pages than you need, and trying to print within that report?

Just a suggestion. I couldn't find an answer other than to put your criteria on a copy of the query, and then when the report opens, the Where clause is applied without code.

For example, if you are passing a CustomerID from a combo box, make a second copy of your query for this special report. Then on the Criteria line in the query designer, add this:

[Forms]![frmMyFormName].[cboCustomerCombo]

When the report runs, the query will take the criteria from the combo box on your form, and will apply it without code. Then use the DoCmd.PrintOut to get your page ranges.

HTH



mmcdonal

Look it up at: http://wrox.books24x7.com
Reply With Quote
  #3 (permalink)  
Old January 22nd, 2008, 10:21 AM
Registered User
Points: 30, Level: 1
Points: 30, Level: 1 Points: 30, Level: 1 Points: 30, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Sep 2007
Location: , , .
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks very much for your reply, and for spending time thinking about my problem. For your information the situation is as follows. Most of my reports from this data base do use predefined queries. However one particular report is for records added or altered since a user entered date. It is that condition which I apply using the WhereClause parameter

The reason for printing individual pages is that sometimes a page will get damaged or fail to print correctly, particularly if printing name/address labels. If that happens then the user has the option to run the report again, selecting which pages to print, so as to avoid the waste of reprinting everything.

I had already thought about creating the query containing the correct selection criteria at runtime. But at present I've taken an easy way out of the problem. I do not allow selection by page number when the report is for records altered since a particular date. This report is usually quite short, since we only use it for recent changes such as the last month or two - rarely more than about 30 records.

I looked at using something like your combo box method. The problem is that this database uses a non-standard way of storing dates, so I need to calculate our type of date value from the user's entry and compare that with the date field in the records. Is there a way of using an expression like your

[Forms]![frmMyFormName].[cboCustomerCombo]

but referring to a variable rather than a control on the form?


Reply With Quote
  #4 (permalink)  
Old January 22nd, 2008, 10:56 AM
Friend of Wrox
Points: 9,611, Level: 42
Points: 9,611, Level: 42 Points: 9,611, Level: 42 Points: 9,611, Level: 42
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Mar 2004
Location: Washington, DC, USA.
Posts: 3,069
Thanks: 0
Thanked 10 Times in 10 Posts
Default

I would use the combo and select the field that is in the proper date format. For example, if your date field was called dtOurDate, then you would do this for the combo box data:

SELECT DISTINCT dtOurDate FROM tblMyTable ORDER BY dtOurDate DESC

This would give the user a way to select the proper date in the proper format, which would be passed to the query in the criteria line.

Otherwise, on the text control where the user is entering or selecting a date, you can put this on the After Update event (after creating a hidden text control on the form called Text0):


Dim sDate As String

sDate = 'some concatenation of the user entry to your date format

Me.Text0 = sDate

Then in the query criteria, do this:

[Forms]![frmMyFormName].[Text0]

Even though the user doesn't see the redisplay of the data, the query will. Then you can use the page selector.

Did that help?


mmcdonal

Look it up at: http://wrox.books24x7.com
Reply With Quote
  #5 (permalink)  
Old January 22nd, 2008, 12:45 PM
Registered User
Points: 30, Level: 1
Points: 30, Level: 1 Points: 30, Level: 1 Points: 30, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Sep 2007
Location: , , .
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Default

That looks as though it is exactly what I need.

Thank you so much.

John

Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
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

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Docmd.Openform problem mkobulni Access VBA 7 August 29th, 2007 09:05 AM
Web Printout problem achonk81 Crystal Reports 1 September 20th, 2005 09:21 PM
DoCmd.FindRecord problem hottnikks_79 Access VBA 1 August 9th, 2005 07:58 AM
updated printout problem jicker VB Databases Basics 2 August 3rd, 2004 08:16 AM
docmd.findrecord problem 02153246XX Access VBA 0 October 27th, 2003 01:58 AM



All times are GMT -4. The time now is 04:03 PM.


Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.