Results 1 to 4 of 4

Thread: [RESOLVED] problem in cancel save

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Jul 2006
    Posts
    131

    Resolved [RESOLVED] problem in cancel save

    i have these two codes for save
    first
    VB Code:
    1. Private Sub Save_Click()
    2.  
    3.  CommonDialog1.Flags = cdlOFNOverwritePrompt
    4.     With CommonDialog1
    5.         .CancelError = True
    6.         .Filter = "Text files (*.txt)|*.txt"
    7.         .DialogTitle = "Save the file..."
    8.         CommonDialog1.Flags = cdlOFNOverwritePrompt
    9.         .ShowSave
    10.             If .filename <> "" Then
    11.                RichTextBox1.SaveFile .filename, rtfText
    12.                RichTextBox2.SaveFile Left(.filename, Len(.filename) - 4) & "first.txt", rtfText
    13.                
    14.             End If
    15.     End With
    16.        
    17.      
    18. End Sub


    second
    VB Code:
    1. Private Sub Command1_Click()
    2. With CommonDialog1
    3.         .CancelError = True
    4.         .Filter = "Text files (*.txt)|*.txt"
    5.         .DialogTitle = "Save the file..."
    6.         .ShowSave
    7.             If .filename <> "" Then
    8.               If fso.fileexists(Left(.filename, Len(.filename) - 4) & "first.txt") Then
    9.                 Form1.RichTextBox1.LoadFile .filename, rtfText
    10.                 RichTextBox2.LoadFile Left(.filename, Len(.filename) - 4) & "first.txt", rtfText
    11.                 txtFileText.Text = RichTextBox2.Text
    12.               Else
    13.                 MsgBox "This File is Not Tagged ,Please Select Another File!"
    14.                 Exit Sub
    15.               End If
    16.             End If
    17.     End With
    18.  
    19.  
    20. End Sub

    i'm getting an error when i click Cancel how can i avoid this error without
    using any msgbox , i just need to cancel saving without effecting the project

  2. #2
    PowerPoster gavio's Avatar
    Join Date
    Feb 2006
    Location
    GMT+1
    Posts
    4,462

    Re: problem in cancel save

    Here's the basic idea:
    VB Code:
    1. On Error GoTo eh
    2.     With CommonDialog1
    3.         .CancelError = True
    4.         'your code...
    5.         .ShowSave
    6.     End With
    7.         Exit Sub
    8. eh:
    9.     If Err <> cdlCancel Then
    10.         MsgBox "Error #" & Err.Number & " - " & Err.Description
    11.     End If

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Jul 2006
    Posts
    131

    Re: problem in cancel save

    thanks gavio

  4. #4

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