Results 1 to 6 of 6

Thread: Form button property Solved

  1. #1

    Thread Starter
    New Member
    Join Date
    Mar 2003
    Posts
    7

    Form button property Solved

    I have a button on a form that opens a save as dialog box. Once the file is saved the file name is set to the text property in a text box on the form but the form closes as soon as the file is saved. I want the form to remain open after the file is saved. Is there a button property or code that will keep the form open?
    Last edited by feistdj; Mar 31st, 2003 at 11:39 PM.

  2. #2
    Frenzied Member Spajeoly's Avatar
    Join Date
    Mar 2003
    Location
    Utah
    Posts
    1,068
    Maybe you cold be a little more specific, let us see the code you are using to do all this and we can probably find the problem.

  3. #3

    Thread Starter
    New Member
    Join Date
    Mar 2003
    Posts
    7

    Button Code

    I just cut and pasted this from my code so I'll explain. The button opens a template Excel file and changes its extension when it is saved. This program had to be coded without the use of OCX or ActiveX controls (for system compatbility reasons) that is why I didn't use the common dialog box method.

    vbcode

    Private Sub project_new_Click()
    ERH_PushStack_TSB ("frmdlgFiles.project_new_Click")

    Dim NewBook As Workbook
    Dim fName As String

    Set NewBook = Application.Workbooks.Add("C:\defproj.cs2")

    fName = Application.GetSaveAsFilename

    If Right(fName, 4) <> ".cs2" Then
    fName = fName & ".cs2"


    End If

    NewBook.SaveAs FileName:=fName


    project_edit.Text = fName


    ThisWorkbook.Saved = False

    End

    /vbcode

  4. #4
    I don't do your homework! opus's Avatar
    Join Date
    Jun 2000
    Location
    Good Old Europe
    Posts
    3,863
    The thing I see is the command "END" which of course will and the whole code not only the Sub! an "End Sub " would be better!

    If you're trying to post code using the Vbcode-tags surround them with [ ], that helps.
    You're welcome to rate this post!
    If your problem is solved, please use the Mark thread as resolved button


    Wait, I'm too old to hurry!

  5. #5
    Frenzied Member Spajeoly's Avatar
    Join Date
    Mar 2003
    Location
    Utah
    Posts
    1,068
    Yea it looks like End might be doing it eh... Try this...

    VB Code:
    1. Private Sub project_new()
    2.     ERH_PushStack_TSB ("frmdlgFiles.project_new_Click")
    3.         Dim NewBook As Workbook
    4.         Dim fName As String
    5.             Set NewBook = Application.Workbooks.Add("C:\defproj.cs2")
    6.                 fName = Application.GetSaveAsFilename
    7.                     If Right(fName, 4) <> ".cs2" Then
    8.                         fName = fName & ".cs2"
    9.                     End If
    10.                 NewBook.SaveAs Filename:=fName
    11.             project_edit.Text = fName
    12.         ThisWorkbook.Saved = False
    13. End Sub

    I am amazed your code worked without "End Sub" at the bottom.

  6. #6

    Thread Starter
    New Member
    Join Date
    Mar 2003
    Posts
    7

    End Sub

    Yes, a stupid oversight. I did have End Sub in the code but it was after the unnecessary End statement. The final code with error handler is:

    VB Code:
    1. Private Sub project_new_Click()
    2. ERH_PushStack_TSB ("frmdlgFiles.project_new_Click")
    3.  
    4. Dim NewBook As Workbook
    5. Dim fName As String
    6.  
    7. Set NewBook = Application.Workbooks.Add("C:\defproj.cs2")
    8.  
    9.     fName = Application.GetSaveAsFilename
    10.    
    11.     If Right(fName, 4) <> ".cs2" Then
    12.     fName = fName & ".cs2"
    13.    
    14.     End If
    15.    
    16.     NewBook.SaveAs FileName:=fName
    17.  
    18. project_edit.Text = fName
    19.  
    20. ThisWorkbook.Saved = False
    21.  
    22. Proc_exit:
    23.     ERH_PopStack_TSB
    24.    Exit Sub
    25.    
    26. Proc_err:
    27.     ERH_Handler_TSB
    28.     Resume Proc_exit
    29.  
    30.  
    31. End Sub

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