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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Trying to print then close form..runtime 2585...newbie stuff probably. 1

Status
Not open for further replies.

ChrisCalvert

Technical User
Mar 18, 2002
231
US
I am trying to have a button open a form print then close the form. When trying to execute the close command I get a runtime 2585. What can I do to make access wait until the printing is finished to close? Here is the code so far:

Private Sub Form_Activate()

DoCmd.DoMenuItem acFormBar, acEditMenu, 8, , acMenuVer70
DoCmd.PrintOut acSelection
'please stop with the 2585...
DoCmd.Close
End Sub
 
Chris,
Do you get a description with that error?

Have you tried adding some error handling and a message box to tell you what access knows?

Just standard stuff:
Code:
Private Sub Form_Activate()
On Error GoTo ErrorHandler

DoCmd.DoMenuItem acFormBar, acEditMenu, 8, , acMenuVer70
DoCmd.PrintOut acSelection
'please stop with the 2585...
DoCmd.Close

Exit_Form_Activate:
exit sub

ErrorHandler:
MsgBox Err.Description
Resume Exit_Form_Activate

End Sub
You may have tried it, but adding this in has helped me a few times to figure out what my error is.
-Dan
 
Then the followup may turn out to be to ignore that error, a la

if Err.number<>2585 then msgbox &quot;Error &quot; & Err.number & &quot; - &quot; & Err.description
Resume

Also basic stuff - no patronizing intended; it just seemed to be a good place to share this.
 
Thinking about it, an
Else DoEvents

might be appropriate there :)

(From someone old enough to remember the term &quot;infinite loop&quot;)
 
Larryww:
Thank you for the reply. The ignore and resume does put me a loop. What is the DoEvents? I am not familliar with this command.
 
It's just good practice to include DoEvents in tight loops, so an app doesn't bind the processor, unjustly and offensively impairing other applications and processes.

Pass this message along to some of the Microsoft developers while you're at it :) It's really lame when it's not considered. Worse than lame.

I can't think of any case where you are hurt by including a Doevents. Technically, you could perfectly validly change your code from

(1st line of code)
(2nd line of code)
(3rd line of code)

to

DoEvents
DoEvents
DoEvents
(1st line of code)
DoEvents
DoEvents
DoEvents
DoEvents
DoEvents
DoEvents
(2nd line of code)
(3rd line of code)
DoEvents
DoEvents
DoEvents

The point is, there's never any harm to including DoEvents, other than taking time away from your own app. perhaps.
 
While off on this tangent, I just remembered - resist ever putting DoEvents in a timer event or code called by a timer event. Don't ask why; &quot;Just Say No!&quot;
 
Thank you Larryww for that info.

Also no patronizing intended from my post. The basic stuff reference only means that Access would put that in for you automatically if you were using a command button wizard.

Chris,
have you been able to get anywhere with this?

-Dan
 
FIrstly, thanks to everyone for the help. But I still am having no luck. The code I have tried has varied from putting in a loop to wait 3 seconds and then close to using a while 'err.num=2585 do'loop to continue trying to close. The description of this error is

'This action can't be carried out while processing a form or report event.'

That happens with this code:

-------------
Private Sub Form_Current()
DoCmd.DoMenuItem acFormBar, acEditMenu, 8, , acMenuVer70
DoCmd.PrintOut acSelection

DoCmd.Close
End Sub

-----------
However, If I attach this same code to a button, and press it as soon as I can, the code executes perfectly. Print, close, no fuss, no muss. However, I don't really want the users to even see this second form. I just want it to print and close. This is linked to another form which is set to open this one.
I cannot determine what 'form or report event.' it believes is running.
Below is some other code I had tried (suggested on another forum) This infinite looped me.

Private Sub Form_Activate()
on error goto Err_Form_Activate
Dim Start

DoCmd.DoMenuItem acFormBar, acEditMenu, 8, , acMenuVer70
DoCmd.PrintOut acSelection

Close_Form:
DoCmd.Close

Exit_Form_Activate:
Exit Sub

Err_Form_Activate
If Err.Number = 2585 Then
Start = Timer ' Set start time.
Do While Timer < Start + 3
'Loops until time has passed , 3 = 3 seconds, change as needed
Loop
else
MsgBox Err.Description
End If
Resume Close_Form

End Sub
 
brainstorming here...

is this line causing a problem when the print command is processed automatically because the form isn't actually selected?

DoCmd.PrintOut acSelection

should it be something more like acCurrent or something like that?

My process to get here was that when Chris puts the same code behind a button, and then clicks the button it works, once you have clicked a button you have brought the focus to the active 'on-top' form. But when access prints automatically, focus is never brought to that form explicitly.

I'm probably way off base, being as new to VBA as I am, but I'm out of ideas otherwise.
-Dan
 
I 'll respond just to kick this atop the queue so someone will see it. I don't have time to answer fully just now.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top