p2p.wrox.com Forums

Need to download code?

View our list of code downloads.


  Return to Index  

vb_howto thread: Unable to trap Cancel button pressed in Commondialog< Printer>


Message #1 by <wintata@m...> on Sun, 13 May 2001 16:16:43 +1000
    I've had problems with CommonDialog in this context myself.  Try something
like the following:

On Error GoTo ErrHandler: pForm.CommonDialog1.ShowPrinter

    Putting it on the same line (or the line previous) has always solved the
problem for me.

- Chuck

----- Original Message -----
From: <wintata@m...>
To: "VB_Howto" <vb_howto@p...>
Sent: Monday, May 14, 2001 1:16 PM
Subject: [vb_howto] Re: Unable to trap Cancel button pressed in Commondialog<
Printer>


> Dear Chuck
>
> Thanks for replying.
> I am using CommonDialog.showprinter to allow the user to (1) set the paper
> size and (2) select the required printer.
> I was under the impression that setting the commondialog.cancelerror 
> false, effectively made the cancel button on this dialog ineffective in that
> it would not create the necessary error that would be trapped by the 'on
> error goto ...'. Conversely setting the CancelError property true should
> result in error trapping by the 'on error goto..'.
>
> This is my code. Because I need the code in more than 1 place in my App I
> have placed it in a module with the form as a parameter. I only need to know
> if the user wishes to print or not.
>
> -----------------------------------------------------
>  Function Select_Printer(pForm As Form) As Boolean
>
>   On Error GoTo ErrHandler
>
>   pForm.CommonDialog1.CancelError = True
>   pForm.CommonDialog1.ShowPrinter
>   Select_Printer = True
>   Exit Function
>
> ErrHandler:
>   Select_Printer = False
> End Function
> '------------------------------------------------------
> The result of this is I get an error 32755 whenever I press the Cancel
> button. This is a 'Run Time error' and does not take the 'on error goto...'
> path.
>
> I am wondering whether to re-install VB because either the comdlg32.ocx or
> .dll have been damaged. I will try it because the behaviour I am getting is
> not what I would have expected.
>
> However if you can see any flaw in the code please feel free to let me know.
>
> Regards
>
> Barney Winton
>

  Return to Index