Solved

Common Dialog and Cancel Button

Posted on 2000-02-16
5
760 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Three Reasons Why Backup is Strategic

Backup is strategic to your business because your data is strategic to your business. Without backup, your business will fail. This white paper explains why it is vital for you to design and immediately execute a backup strategy to protect 100 percent of your data.

Question has a verified solution.

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

Suggested Solutions

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.
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
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.

740 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