Go Back   Access World Forums > Microsoft Access Discussion > Reports

 
Reply
 
Thread Tools Rate Thread Display Modes
Old 06-06-2019, 07:22 AM   #1
yaya
Newly Registered User
 
Join Date: Dec 2018
Posts: 18
Thanks: 11
Thanked 0 Times in 0 Posts
yaya is on a distinguished road
Red face Automated Report Printing "This document was previously formatted for printer..."

Hello,

We recently moved a database to a new server and have been experiencing this issue irregularly, seemingly more and more often:

Every morning there is an auto process kicked off and multiple reports are being printed. Usually this one report hangs up and when it tries to print it throws up that "The document was previously formatted for printer <PRINTERNAME>, but that printer isn't available. Do you want to use the default printer <DEFAULTPRINTERNAME>" dialog box.

When I come in the morning and see this I usually go to the page tab and reselect <PRINTERNAME>, then hit "OK" and it will resume the process fine.

I dont know why this one report seems to forget its printer in the morning during the auto process, but once I manually run the code it works fine. Has anyone had experience with this issue before?

I made sure to open the page setup for the report and that it is properly configured to print to <PRINTERNAME>

I also tried implementing this function to manually select <PRINTERNAME> before printing the report and unfortunately ive had no luck with it.

Code:
Public Function ChoosePrinter(strPrinter As String, strReport As String)
     Dim prtCurrent As Printer
     Dim prtDefault As Printer
     
     'Save current default printer
     Set prtDefault = Application.Printer
       
     'Select a specific printer as new default printer
     Application.Printer = Printers(strPrinter)
     
     'Print the report
     DoCmd.OpenReport strReport
     
     'Set printer back to former default printer
     Application.Printer = prtDefault
End Function
Any help with this is much appreciated!

yaya is offline   Reply With Quote
Old 06-06-2019, 07:26 AM   #2
theDBguy
Iím here to help
 
theDBguy's Avatar
 
Join Date: Oct 2018
Location: SunnySandyEggo
Posts: 6,424
Thanks: 58
Thanked 1,409 Times in 1,390 Posts
theDBguy has a spectacular aura about theDBguy has a spectacular aura about
Re: Automated Report Printing "This document was previously formatted for printer..."

Hi. Just curious, if you go to the design view of the printer, what printer is it set to?
__________________
Just my 2 cents...

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
|
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
|
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
theDBguy is online now   Reply With Quote
Old 06-06-2019, 07:34 AM   #3
yaya
Newly Registered User
 
Join Date: Dec 2018
Posts: 18
Thanks: 11
Thanked 0 Times in 0 Posts
yaya is on a distinguished road
Re: Automated Report Printing "This document was previously formatted for printer..."

Quote:
Originally Posted by theDBguy View Post
Hi. Just curious, if you go to the design view of the printer, what printer is it set to?
When I go to design and then over to the Page Setup tab, the Page Setup dialog box opens and then if I go to the page tab in that, the correct specific printer <PRINTERNAME> is selected.

Perhaps I need to have it selected to the default printer and then briefly change the default to <PRINTERNAME> with VBA before opening the report?

I thought this is what the function above does but maybe the report needs to be set to the default in order for it to work?

yaya is offline   Reply With Quote
Old 06-06-2019, 07:45 AM   #4
theDBguy
Iím here to help
 
theDBguy's Avatar
 
Join Date: Oct 2018
Location: SunnySandyEggo
Posts: 6,424
Thanks: 58
Thanked 1,409 Times in 1,390 Posts
theDBguy has a spectacular aura about theDBguy has a spectacular aura about
Re: Automated Report Printing "This document was previously formatted for printer..."

Quote:
Originally Posted by yaya View Post
When I go to design and then over to the Page Setup tab, the Page Setup dialog box opens and then if I go to the page tab in that, the correct specific printer <PRINTERNAME> is selected.

Perhaps I need to have it selected to the default printer and then briefly change the default to <PRINTERNAME> with VBA before opening the report?

I thought this is what the function above does but maybe the report needs to be set to the default in order for it to work?
Hi. I was thinking along the same line. I'd say give it a try and hope for the best.
__________________
Just my 2 cents...

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
|
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
|
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
theDBguy is online now   Reply With Quote
The Following User Says Thank You to theDBguy For This Useful Post:
yaya (06-06-2019)
Old 06-06-2019, 07:52 AM   #5
yaya
Newly Registered User
 
Join Date: Dec 2018
Posts: 18
Thanks: 11
Thanked 0 Times in 0 Posts
yaya is on a distinguished road
Re: Automated Report Printing "This document was previously formatted for printer..."

Quote:
Originally Posted by theDBguy View Post
Hi. I was thinking along the same line. I'd say give it a try and hope for the best.
Yeah I just modified the auto process to only do that and then i re ran the scheduled task that runs in the morning and it worked. Although i wont know for sure until tomorrow morning. Fingers crossed!

If this works i will feel silly because its something i should have already tried. Oh well, sometimes writing out my problem on here helps me think more clearly.

Will let you know how it goes tomorrow, thanks for your responses!
yaya is offline   Reply With Quote
Old 06-06-2019, 07:58 AM   #6
theDBguy
Iím here to help
 
theDBguy's Avatar
 
Join Date: Oct 2018
Location: SunnySandyEggo
Posts: 6,424
Thanks: 58
Thanked 1,409 Times in 1,390 Posts
theDBguy has a spectacular aura about theDBguy has a spectacular aura about
Re: Automated Report Printing "This document was previously formatted for printer..."

Quote:
Originally Posted by yaya View Post
Yeah I just modified the auto process to only do that and then i re ran the scheduled task that runs in the morning and it worked. Although i wont know for sure until tomorrow morning. Fingers crossed!

If this works i will feel silly because its something i should have already tried. Oh well, sometimes writing out my problem on here helps me think more clearly.

Will let you know how it goes tomorrow, thanks for your responses!
Okay, we're crossing our fingers too. Good luck!
__________________
Just my 2 cents...

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
|
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
|
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
theDBguy is online now   Reply With Quote
Old 06-06-2019, 08:23 AM   #7
gemma-the-husky
Super Moderator
 
gemma-the-husky's Avatar
 
Join Date: Sep 2006
Location: UK
Posts: 13,814
Thanks: 56
Thanked 1,028 Times in 994 Posts
gemma-the-husky is a name known to all gemma-the-husky is a name known to all gemma-the-husky is a name known to all gemma-the-husky is a name known to all gemma-the-husky is a name known to all gemma-the-husky is a name known to all
Re: Automated Report Printing "This document was previously formatted for printer..."

do you actually want the designated printer for that report?
It sounds like its not installed on your PC (or not named correctly), so instead it reformats the report for the default printer. If you are in preview mode, you can then pick a different printer - but otherwise it will just print to the default, I think.

NB - setting a specific printer

Note that you can't just set a printer. You have to set the default printer to the one you want, and then reset it back to the default after you have printed. Note also that printer names are case sensitive in access.


set application.printer = printers("PrinterNameRequired") to set it. This is the case sensitive bit.
In practice it's easier to iterate the printers collection until you find the right one, as testing for the printer name is NOT case sensitive

then
set application.printer = nothing to clear it.


Hope that helps

__________________
Dave (Male!)
Gemma was my dog

if a poster helps you, please click the scales at the bottom left of this posting, or use the thanks button alongside.
gemma-the-husky is offline   Reply With Quote
Old 06-06-2019, 08:43 AM   #8
yaya
Newly Registered User
 
Join Date: Dec 2018
Posts: 18
Thanks: 11
Thanked 0 Times in 0 Posts
yaya is on a distinguished road
Re: Automated Report Printing "This document was previously formatted for printer..."

Quote:
Originally Posted by gemma-the-husky View Post
do you actually want the designated printer for that report?
It sounds like its not installed on your PC (or not named correctly), so instead it reformats the report for the default printer. If you are in preview mode, you can then pick a different printer - but otherwise it will just print to the default, I think.

NB - setting a specific printer

Note that you can't just set a printer. You have to set the default printer to the one you want, and then reset it back to the default after you have printed. Note also that printer names are case sensitive in access.
Is this not what the function posted does? It doesn't set it to nothing when its done but rather it stores the original default until the print is done and then sets it back to that afterward.

Quote:
Originally Posted by gemma-the-husky View Post
set application.printer = printers("PrinterNameRequired") to set it. This is the case sensitive bit.
In practice it's easier to iterate the printers collection until you find the right one, as testing for the printer name is NOT case sensitive

then
set application.printer = nothing to clear it.


Hope that helps
I didnt know the printer name was case sensitive, as I rarely encounter something thats case sensitive in access. Thank you for that info.

Sadly, I think I am passing it correctly in the function right now and currently when I see the error box that says "the report was previously formatted for <PRINTERNAME>" , when I manually reselect <PRINTERNAME> from the dropdown of available printers and hit "OK" it is displayed exactly the same as the way I pass it originally but for some reason it will then work.
yaya is offline   Reply With Quote
Old 06-06-2019, 09:25 AM   #9
gemma-the-husky
Super Moderator
 
gemma-the-husky's Avatar
 
Join Date: Sep 2006
Location: UK
Posts: 13,814
Thanks: 56
Thanked 1,028 Times in 994 Posts
gemma-the-husky is a name known to all gemma-the-husky is a name known to all gemma-the-husky is a name known to all gemma-the-husky is a name known to all gemma-the-husky is a name known to all gemma-the-husky is a name known to all
Re: Automated Report Printing "This document was previously formatted for printer..."

Ok - I should have seen your code.

Maybe it IS a case issue with the printer name

try this - this is the normal recommendation for setting a printer - iterate the collection. put a breakpoint in there, or add msgboxes to show it checking the printers, if you like, so you can see what it is doing.

You can test this code, easily enough.


Code:
function setprinter (printername as string) as boolean

dim ptr as printer

    for each ptr in application,printers
         
         if ptr.name = printername then 'this test is not case sensitive
              set application.printer = ptr
              setprinter = true
              exit function
         end if
   next

  'printer was not found
  setprinter = false
end function


function clearprinter ()
  set application.printer=nothing
end function
usage

Code:
if requiredprinter<>"" then
    if not setprinter(requiredprinter) then
        msgbox "could not set printer to " & requiredprinter
    end if
end if

docmd.openreport etc 
clearprinter 'won't hurt
__________________
Dave (Male!)
Gemma was my dog

if a poster helps you, please click the scales at the bottom left of this posting, or use the thanks button alongside.

Last edited by gemma-the-husky; 06-06-2019 at 09:32 AM.
gemma-the-husky is offline   Reply With Quote
The Following User Says Thank You to gemma-the-husky For This Useful Post:
yaya (06-06-2019)
Old 06-06-2019, 09:58 AM   #10
yaya
Newly Registered User
 
Join Date: Dec 2018
Posts: 18
Thanks: 11
Thanked 0 Times in 0 Posts
yaya is on a distinguished road
Re: Automated Report Printing "This document was previously formatted for printer..."

Quote:
Originally Posted by gemma-the-husky View Post
Ok - I should have seen your code.

Maybe it IS a case issue with the printer name

try this - this is the normal recommendation for setting a printer - iterate the collection. put a breakpoint in there, or add msgboxes to show it checking the printers, if you like, so you can see what it is doing.

You can test this code, easily enough.


Code:
function setprinter (printername as string) as boolean

dim ptr as printer

    for each ptr in application,printers
         
         if ptr.name = printername then 'this test is not case sensitive
              set application.printer = ptr
              setprinter = true
              exit function
         end if
   next

  'printer was not found
  setprinter = false
end function


function clearprinter ()
  set application.printer=nothing
end function
usage

Code:
if requiredprinter<>"" then
    if not setprinter(requiredprinter) then
        msgbox "could not set printer to " & requiredprinter
    end if
end if

docmd.openreport etc 
clearprinter 'won't hurt

I think switching the configuration from the specific printer <PRINTERNAME> to the default printer may have solved the issue. I tested it out by re running the scheduled task and it worked but I wont know for sure until tomorrow morning.

if not, I will try this out and reply back letting you know on Monday. Thanks for the help!
yaya is offline   Reply With Quote
Old 06-07-2019, 09:47 AM   #11
yaya
Newly Registered User
 
Join Date: Dec 2018
Posts: 18
Thanks: 11
Thanked 0 Times in 0 Posts
yaya is on a distinguished road
Re: Automated Report Printing "This document was previously formatted for printer..."

Hey Gemma, I tried to reply to your private message but I dont have enough posts yet to do so hahaha

So it appeared to be fixed for that one report that was initially causing the issue, but then a report that gets printed after had the same thing happen.

So I reconfigured all of the reports that were set to a specific printer to the default printer instead and made the adjustments in the code to change the default printer when necessary for them. hopefully now it will work.

Because the initial report didnt cause any issue today i am optimistic it will!

Thanks for following up, when I know for sure everything is resolved I will post again on the thread (probably next week)

yaya is offline   Reply With Quote
Reply

Tags
automation , print problem , report print

Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Print to .XPS with the printer "Microsoft XPS Document Write" megatronixs Modules & VBA 8 09-15-2016 01:19 AM
If "TableA.FieldA" exists in "TableB.FieldB" then return "1" else "2" shdale Queries 8 10-29-2014 05:20 AM
Report Previously Formatted for Printer X.... AggieLJ Reports 2 03-15-2010 11:25 AM
printing "Original," "copy" on a form Durien512 Forms 1 03-28-2006 12:19 PM
Printing from VB using the "Printer" object Keizo Modules & VBA 0 09-05-2005 01:19 AM




All times are GMT -8. The time now is 02:17 PM.


Microsoft Access Help
General
Tables
Queries
Forms
Reports
Macros
Modules & VBA
Theory & Practice
Access FAQs
Code Repository
Sample Databases
Video Tutorials

Featured Forum post


Sponsored Links


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
(c) copyright 2017 Access World