Results 1 to 5 of 5

Thread: cancel button not working properly while using Common dialog

  1. #1

    Thread Starter
    New Member
    Join Date
    Oct 2005
    Posts
    3

    cancel button not working properly while using Common dialog

    hi,

    I m using VB macros in the Microsoft Project Plan to convert the plan into xml using the common dialog.
    Its working fine for Save the MPP into xml format.

    However once i save it and then try to use the Save as menu, it captures the name of the file which i saved earlier and even if i cancel the dialog box, the file is saved using that name.

    im attaching the code for reference:
    DialogForm.CommonDialog1.Filter = "All Xml (*.xml)"
    DialogForm.CommonDialog1.ShowSave
    If (DialogForm.CommonDialog1.fileName = "") Then

    End If
    If (DialogForm.CommonDialog1.fileName <> "") Then
    xmlFileName = DialogForm.CommonDialog1.fileName + ".xml"

    anybody has any idea, why the problem is coming.

  2. #2
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: cancel button not working properly while using Common dialog

    VBA question...moved to Office Development.

  3. #3
    Frenzied Member zaza's Avatar
    Join Date
    Apr 2001
    Location
    Borneo Rainforest Habits: Scratching
    Posts
    1,486

    Re: cancel button not working properly while using Common dialog

    Hi,

    What I normally do is set the property Cancelerror = True, which means that it will generate an error if cancel is pressed. Then you can trap it with the line "On error goto cancelled", and stick a "cancelled:" section of code at the bottom of the sub. Like so:

    VB Code:
    1. On Error GoTo cancelled:
    2. DialogForm.CommonDialog1.Filter = "All Xml (*.xml)"
    3. DialogForm.CommonDialog1.cancelerror = True
    4. DialogForm.CommonDialog1.ShowSave
    5.  
    6. If (DialogForm.CommonDialog1.fileName <> "") Then
    7. xmlFileName = DialogForm.CommonDialog1.fileName + ".xml"
    8.  
    9. Exit Sub
    10. cancelled:
    11. msgbox "You pressed Cancel"


    Alternatively, there are builtin MSOffice Dialogs, which mean that you don't need the CommonDialog control. Check for "Dialog" in the VBA help for a fully coded example.

    HTH

    zaza

  4. #4

    Thread Starter
    New Member
    Join Date
    Oct 2005
    Posts
    3

    Re: cancel button not working properly while using Common dialog

    thanks a lot...the on Error thing worked...

  5. #5
    Frenzied Member zaza's Avatar
    Join Date
    Apr 2001
    Location
    Borneo Rainforest Habits: Scratching
    Posts
    1,486

    Re: cancel button not working properly while using Common dialog

    Glad to hear it. Can you mark this as "Resolved" then? Edit your first post and change the symbol to the green tick.

    Cheers

    zaza

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width