Lotusscript: Send and Print button

Hi, I wanted to create a send and print button on the memo form. Fine.

I want it to spellcheck & send (does by default), then present the print dialogue. At this point the user MUST print the document.

I can’t force the script to go back to the print dialogue though!

Here’s the code (a bit messy but I don’t generally do Lotusscript!):

Sub Click(Source As Button)

Dim workspace As New NotesUIWorkspace

Dim uidoc As NotesUIDocument

Dim x As Integer

Set uidoc = workspace.CurrentDocument

On Error Goto errhandle1

Call uidoc.Send

Goto printmand

printmand:

On Error Goto errhandle2

Call uidoc.Print

Call uidoc.Close

Exit Sub

errhandle1:

Exit Sub

errhandle2:

Goto printmand

End Sub

Does anyone have any ideas???

Thanks

Elton

Subject: Lotusscript: Send and Print button

Well, if there’s an error you’re not actually trapping it, and it’s going into an infinite loop here:

printmand:

On Error Goto errhandle2

Call uidoc.Print

Call uidoc.Close

Exit Sub

…

errhandle2:

Goto printmand

So it gets to printmand, hits an error, and goes to errhandle2, which just sends it right back to printmand. Not good. I’m not certain why you’re bothering with two errorhandlers, especially since neither of them tells you what the error is if one occurs. I would try something like this:

Sub Click(Source As Button)

On Error Goto errhandle

Dim workspace As New NotesUIWorkspace

Dim uidoc As NotesUIDocument

Set uidoc = workspace.CurrentDocument

Call uidoc.Send

Call uidoc.Print

Call uidoc.Close

Exit Sub

errhandle:

msgbox "error at line " & erl & ": " & error

exit sub

End Sub

Subject: RE: Lotusscript: Send and Print button

Thanks Esther, I think you missed my poorly made point. I could not stop the user from cancelling out of printing.

Cancelling the spell checker throws up an error which is trappable. I thought that cancelling printing would do the same (But it doesn’t). So I needed the agent to do something different depending on where in the procedure the error occured - hence two handlers. I actually wnated to put the agent into an endless loop if the user clicked on the cancel button in the print dialogue.

In the end I used a more simple procedure (much like your own) where I forced the print command to push the job to the default printer without showing the print dialog:

Sub Click(Source As Button)

Dim workspace As New NotesUIWorkspace

Dim uidoc As NotesUIDocument

Set uidoc = workspace.CurrentDocument

On Error Goto errhandle1

Call uidoc.Send

Call uidoc.Print(1)

Call uidoc.Close

Exit Sub

errhandle1:

Exit Sub

End Sub