cancellation of common dialog box 
Author Message
 cancellation of common dialog box

Hi,

where is the event when I click the cancel button of
common dialog box?

Thanks in advance.

andy



Sat, 05 Jun 2004 23:14:49 GMT  
 cancellation of common dialog box
Well... if you set the controls CancelError property = True, clicking Cancel
raises an error..
'==============
Private Sub cmdSelectFile_Click()
   On Error GoTo ErrorTrap

   With CommonDialog1
      .CancelError = True
      .ShowOpen
   End With

'Add code here to do the chore that needs to be done
'when they don't press cancel..

Terminate:
   Exit Sub

ErrorTrap:
   If Err.Number = cdlCancel Then
      MsgBox "User clicked Cancel"
   Else
      MsgBox "Error " & Err.Number & vbCrLf & Err.Description
   End If
   Resume Terminate
End Sub
'==============

--
Ken Halter
MS-MVP-VB
http://www.vbsight.com
Please respond only to the newsgroups so all can benefit.
Besides.. I check my email only once a week :-)


Quote:
> Hi,

> where is the event when I click the cancel button of
> common dialog box?

> Thanks in advance.

> andy



Sat, 05 Jun 2004 23:25:24 GMT  
 cancellation of common dialog box
Thank you very much.
It is amazing I can always get quick and right response in
this group.

andy

Quote:
>-----Original Message-----
>Well... if you set the controls CancelError property =

True, clicking Cancel
Quote:
>raises an error..
>'==============
>Private Sub cmdSelectFile_Click()
>   On Error GoTo ErrorTrap

>   With CommonDialog1
>      .CancelError = True
>      .ShowOpen
>   End With

>'Add code here to do the chore that needs to be done
>'when they don't press cancel..

>Terminate:
>   Exit Sub

>ErrorTrap:
>   If Err.Number = cdlCancel Then
>      MsgBox "User clicked Cancel"
>   Else
>      MsgBox "Error " & Err.Number & vbCrLf &
Err.Description
>   End If
>   Resume Terminate
>End Sub
>'==============

>--
>Ken Halter
>MS-MVP-VB
>http://www.vbsight.com
>Please respond only to the newsgroups so all can benefit.
>Besides.. I check my email only once a week :-)



>> Hi,

>> where is the event when I click the cancel button of
>> common dialog box?

>> Thanks in advance.

>> andy

>.



Sun, 06 Jun 2004 02:45:13 GMT  
 cancellation of common dialog box
There is no event... you have to code for the resulting "error" condition...
There is no need for an "event" for cancel because the common dialog box is
shown as modal, the routine that displayed the common dialog is basically
suspended until OK or CANCEL is pressed (and the dialog is dismissed)

For printer selection I use
    on error resume next
    and after calling the common dialog box I check the value of hDC.. if
it's zero, the dialog was cancelled and no printing is done, I end the
routine gracefully.
If hDC IS presnt, I invoke the proper print method for what I want...

The examples show using on error goto CancelPrint
and then having a label in your routine that gets control when the cancel
button is pressed.

Don Russell


Quote:
> Hi,

> where is the event when I click the cancel button of
> common dialog box?

> Thanks in advance.

> andy



Mon, 07 Jun 2004 11:52:56 GMT  
 cancellation of common dialog box
I have a correction for my code... that's what I get for going by memory...

But here it is... cut/paste from a working app... YMMV :-)

    Const AllText As Long = cdlPDAllPages + cdlPDReturnDC + cdlPDNoPageNums
    Const SelText As Long = cdlPDSelection + cdlPDReturnDC + cdlPDNoPageNums

    With Me.CommonDialog1(0)
        If Me.RichTextBox1.SelLength = 0 Then
           .flags = AllText
        Else
           .flags = SelText
        End If
        .ShowPrinter
        If .hDC <> Null Then
            Me.RichTextBox1.SelPrint .hDC
        End If
    End With

No need to mess with the "on error" stuff at all, I like this, I think it's
pretty clean/easy to understand/maintain  :-)

if I were to write this again, I'd probably use the iif function to set the
dialog flags.... but that's a nit.. :-)

Regards,
Don Russell


Quote:
> There is no event... you have to code for the resulting "error"
condition...
> There is no need for an "event" for cancel because the common dialog box
is
> shown as modal, the routine that displayed the common dialog is basically
> suspended until OK or CANCEL is pressed (and the dialog is dismissed)

> For printer selection I use
>     on error resume next
>     and after calling the common dialog box I check the value of hDC.. if
> it's zero, the dialog was cancelled and no printing is done, I end the
> routine gracefully.
> If hDC IS presnt, I invoke the proper print method for what I want...

> The examples show using on error goto CancelPrint
> and then having a label in your routine that gets control when the cancel
> button is pressed.

> Don Russell



> > Hi,

> > where is the event when I click the cancel button of
> > common dialog box?

> > Thanks in advance.

> > andy



Mon, 07 Jun 2004 13:53:38 GMT  
 
 [ 5 post ] 

 Relevant Pages 

1. Centering a Open Dialog box using the Common dialog

2. Showing detail view in Common Dialog Box

3. Common Dialog Box Error

4. Common Dialog Box code

5. Common Dialog Box in VBA

6. Selecting files from common dialog box in access97

7. Common dialog box

8. Open File Common Dialog Boxes in Access95 VBA Code

9. Using Common Dialog Boxes to Get Directories

10. common dialog box in vba

11. How To show only directories with Common Dialog Box for open files

12. COMMON DIALOG BOX - VB

 

 
Powered by phpBB® Forum Software