Automated Report Printing "This document was previously formatted for printer..." (1 Viewer)

yaya

Registered User.
Local time
Today, 01:27
Joined
Dec 4, 2018
Messages
18
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!
 

theDBguy

I’m here to help
Staff member
Local time
Today, 01:27
Joined
Oct 29, 2018
Messages
21,357
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?
 

yaya

Registered User.
Local time
Today, 01:27
Joined
Dec 4, 2018
Messages
18
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?

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?
 

theDBguy

I’m here to help
Staff member
Local time
Today, 01:27
Joined
Oct 29, 2018
Messages
21,357
Re: Automated Report Printing "This document was previously formatted for printer..."

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.
 

yaya

Registered User.
Local time
Today, 01:27
Joined
Dec 4, 2018
Messages
18
Re: Automated Report Printing "This document was previously formatted for printer..."

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!
 

theDBguy

I’m here to help
Staff member
Local time
Today, 01:27
Joined
Oct 29, 2018
Messages
21,357
Re: Automated Report Printing "This document was previously formatted for printer..."

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!
 

gemma-the-husky

Super Moderator
Staff member
Local time
Today, 08:27
Joined
Sep 12, 2006
Messages
15,613
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
 

yaya

Registered User.
Local time
Today, 01:27
Joined
Dec 4, 2018
Messages
18
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.

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.

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.
 

gemma-the-husky

Super Moderator
Staff member
Local time
Today, 08:27
Joined
Sep 12, 2006
Messages
15,613
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 '[COLOR="Red"]this test is not case sensitive[/COLOR]
              set application.printer = ptr
              setprinter = true
              exit function
         end if
   next

  '[COLOR="red"]printer was not found[/COLOR]
  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
 
Last edited:

yaya

Registered User.
Local time
Today, 01:27
Joined
Dec 4, 2018
Messages
18
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 '[COLOR="Red"]this test is not case sensitive[/COLOR]
              set application.printer = ptr
              setprinter = true
              exit function
         end if
   next

  '[COLOR="red"]printer was not found[/COLOR]
  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

Registered User.
Local time
Today, 01:27
Joined
Dec 4, 2018
Messages
18
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)
 

Users who are viewing this thread

Top Bottom