Solved

Common Dialog and Cancel Button

Posted on 2000-02-16
5
732 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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

I see at least one EE question a week that pertains to using temporary tables in MS Access.  But surprisingly, I was unable to find a single article devoted solely to this topic. I don’t intend to describe all of the uses of temporary tables in t…
Describes a method of obtaining an object variable to an already running instance of Microsoft Access so that it can be controlled via automation.
In Microsoft Access, learn different ways of passing a string value within a string argument. Also learn what a “Type Mis-match” error is about.
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…

760 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now