Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Printing after DoCmd.OutputTo and DeleteFile statements not working

Status
Not open for further replies.

Bresart

Programmer
Feb 14, 2007
314
ES
Hi, i have a form with a Print button, with the next code:

DoCmd.OutputTo acOutputReport, "infGeneralParcial_paginador", acFormatSNP, CurrentProject.Path & "\temp1.snp", False
DeleteFile ("" & CurrentProject.Path & "\temp1.snp")
DoCmd.OutputTo acOutputReport, "infGeneralSubinfINDICE_paginador", acFormatSNP, CurrentProject.Path & "\temp2.snp", False
DeleteFile ("" & CurrentProject.Path & "\temp2.snp")
If Me.Marco45.Value = 1 Then 'vista prel.
DoCmd.OpenReport "infGeneralParcial", acViewPreview
DoCmd.Close acForm, "frmImprimir"
DoCmd.SelectObject acReport, "infGeneralParcial"
DoCmd.Maximize
DoCmd.ShowToolbar "Ventana2", acToolbarYes
DoCmd.ShowToolbar "Vista Preliminar", acToolbarNo

ElseIf Me.Marco45.Value = 2 Then 'impr. a impresora
Application.Echo False
DoCmd.OpenReport "infGeneralParcial", acViewPreview
DoCmd.RunCommand acCmdPrint
DoCmd.Close acReport, "infGeneralParcial"

ElseIf Me.Marco45.Value = 3 Then 'impr. a archivo
DoCmd.OutputTo acOutputReport, "infGeneralParcial", acFormatSNP, , True
End if

Application.Echo True


The Marco45 is an options frame in which the printing mode is selected. That code is not working, none of the three if statements enter (i have put msg boxes for testing that). But i have tested that if the two DoCmd.OutputTo and the two DeleteFile statemens at the beginning of the procedure are deleted, the if statement for the printing selected option enters correctly.

Is there any solution for keeping the two DoCmd.OutputTo and the two DeleteFile statements in a working code?

Thanks for any help given.
 
Have you tried a message box in the frame's on click to tell you what the value of the frame is after each click?

Msgbox Me.Macro45.Value



ProDev, MS Access Applications
Visit me at ==>
May God bless you beyond your imagination!!!
 
Thanks LonnieJohnson.

I have tried it, the value changes correctly, but the code doesn't enter according to the current value.
 
What exactly are you doing with your first 4 lines of code? It looks to me like you're creating a file, immediately deleting it (without doing anything with it) then creating a second file and immediately deleting it also.

Also, according to the Help Files, the syntax for DeleteFile() is

object.DeleteFile filespec[, force]

where object is required; you appear to be missing this. And finally, from Help:

"An error occurs if no matching files are found. The DeleteFile method stops on the first error it encounters. No attempt is made to roll back or undo any changes that were made before an error occurred."

Maybe this is why the code is being deep-sixed.

The Missinglinq

Richmond, Virginia

There's ALWAYS more than one way to skin a cat!
 
No On Error instruction in the sub above the code you posted ?

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
missinglinq, what these first 4 lines of code do is to make an index for the report that is opened after. In the statement

object.DeleteFile filespec[, force]

what the argument 'object' must be?


PHV, yes, the procedure also has an error handling.


Thanks for reply.
 
So, disable the error handling to discover what happens ...

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Thanks PHV. Dissabling the error handling the same bechaviour occurs: nothing happens.

Just the if statement doesn't enter.
 
Did you debug your code step by step ?

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Is there anyway you can email the database to me?

lonniejohnson @ prodev.us

Remove the spaces.

ProDev, MS Access Applications
Visit me at ==>
May God bless you beyond your imagination!!!
 
PHV, i have put an interruption point in the first if line, and that line doesn't enter (the VBE doesn't open). Did you mean this?

LonnieJohnson, i think there's no way of sending to you the DB, its size is 450 MB, i would try to send you only that form and that reports.

Thanks.
 
Put the breakpoint earlier in the sub.

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
PHV, i have done that and checked that the problem is with the DeleteFile statement. The breakpoint in the first DeleteFile statement doesn't enter.

I would need to do it in other way, with

object.DeleteFile filespec[, force]

like missinglinq said. But i have tried with:

Dim fso as Object
Set fso = CreateObject("Scripting.FileSystemObject")
fso.DeleteFile CurrentProject.Path & "\temp1.snp", True

and tested that a breakpoint in the Set fso statement line neither enters.

However, in both cases, a breakpoint in the previous DoCmd.OutputTo statement enters.

Thanks.
 
I have tried to put the line

DoCmd.OutputTo acOutputReport, "infGeneralParcial_paginador", acFormatSNP, CurrentProject.Path & "\temp1.snp", False

at the beginning of the procedure and tested that this line enters but the next line after it doesn't enter.

The problem seems to be the DoCmd.OutputTo statement.
 
Can you open the report without the code? Is there a problem with the report?

ProDev, Builders of Affordable Software Applications
Visit me at ==>
May God bless you beyond your imagination!!!
 
Yes LonnieJohnson, it was a report problem.

Thanks.
 
Ok, are you fine now? Do you need help with the report?

ProDev, Builders of Affordable Software Applications
Visit me at ==>
May God bless you beyond your imagination!!!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top