Solved

Common Dialog and Cancel Button

Posted on 2000-02-16
5
754 Views
Last Modified: 2010-05-18
I am using the Common Dialog control to allow a user to save an access report to a word doc(acutally RTF).  If the user press cancel on the save as form of the common Dialog i want it to exit the sub all together.

So far no such luck in it working.  It either stills saves the document or drops to the default save as for RTF files.

TIA
John
0
Comment
Question by:JTD3
5 Comments
 
LVL 1

Expert Comment

by:SeanGraflund
ID: 2527754
JTD3,

try this in your sub ..


Sub SaveAsRTF()

On Error Goto Err_Handle


'This is where your code is

Err_Handle:
    Exit Sub






0
 

Author Comment

by:JTD3
ID: 2527807
I have encluded the on error routine, but it does not trigger the exit of the function.

Any other ideas?

John
0
 
LVL 10

Expert Comment

by:brewdog
ID: 2527877
Here is code that we use to do just what you're talking about:

Private Function FileDialog() as String

On Error GoTo FileDialogError

FileDialog = ""                   'start as empty string so we always have a string

With CommonDialog1
    .DialogTitle = sTitle
    .Filter = sFilter
    .Flags = lFlags
    .FileName = sFileName
    .ShowSave
End With

FileDialog = CommonDialog1.FileName

Exit Function

FileDialogError:
    MsgBox Err.Number & ", " & Err.Description
    FileDialog = ""

End Function

This way if they cancel and/or hit some kind of an error, this function still returns a string. You can do the same thing with the code by declaring a string variable, setting it to an empty string, and then setting it to an empty-string on the error, too.

Hope that helps . . .

brewdog
0
 
LVL 6

Accepted Solution

by:
blakeh1 earned 20 total points
ID: 2528093
Here is a routine thaqt will check for the cancel error
Private Sub Command1_Click()
             Dim oCmnDlg As CommonDialog
             Dim strFormat As String
             Dim strFileName As String
             Set oCmnDlg = Me!cdlgSave.Object
             On Error GoTo Export_Err
             With oCmnDlg
                ' Clear the file name before prompting.
                .FileName = ""
                ' Prompt the user if the file already exists.
                .Flags = cdlOFNOverwritePrompt + cdlOFNHideReadOnly
                ' Determine if the cancel button was pressed.
                .CancelError = True
 
                .Filter = _
                "MS-DOS Text (*.txt)|*.txt|Rich Text Format (*.rtf)|*.rtf" _
                & "|Microsoft Excel (*.xls)|*.xls"
 
                .FilterIndex = 1
 
                ' Default the initial directory to "C:\My Documents".
                .InitDir = "C:\My Documents"
                .ShowSave
 
                ' Determine what file type was selected; then save the
                ' file in that format.
                Select Case .FilterIndex
                   Case 1 ' MS-DOS Text Format.
                      strFormat = acFormatTXT
 
                   Case 2 ' Rich Text Format.
                      strFormat = acFormatRTF
 
                   Case 3 ' Microsoft Excel Format.
                      strFormat = acFormatXLS
                End Select
                strFileName = .FileName
             End With
             DoCmd.OutputTo acOutputTable, "Generaltbl", _
                strFormat, strFileName
             Exit Sub
 
Export_Exit:
             Exit Sub
 
Export_Err:
             ' Check to see if the cancel button was pressed.
             If Err.Number = 32755 Then 'cancel was used
                Resume Export_Exit
             Else
                MsgBox Err.Number & ",    " & Err.Description
             End If
             Resume Export_Exit
End Sub
0
 

Author Comment

by:JTD3
ID: 2529006
Worked like a charm.  Thank you very much.
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Overview: This article:       (a) explains one principle method to cross-reference invoice items in Quickbooks®       (b) explores the reasons one might need to cross-reference invoice items       (c) provides a sample process for creating a M…
As tax season makes its return, so does the increase in cyber crime and tax refund phishing that comes with it
With Microsoft Access, learn how to start a database in different ways and produce different start-up actions allowing you to use a single database to perform multiple tasks. Specify a start-up form through options: Specify an Autoexec macro: Us…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

821 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question