Consulting

Results 1 to 2 of 2

Thread: Exit userform and save changes

  1. #1

    Exit userform and save changes

    Hi there, I want to save all the Data the user has entered before he leaves the program.
    1) how can I store I store the last userform (the one that displays the results) as image in a separate folder?

    2) can anyone give me a nice alternative way to exit the last userform. I'm currently using this code (in the "This Workbook" sheet):

    [VBA]
    Private Sub Workbook_BeforeClose(Cancel As Boolean)
    If (MsgBox(prompt:=" Do you really want to close?", Buttons:=vbOKCancel) = vbCancel) Then
    Cancel = True
    Else
    Cancel = False
    End If

    If Cancel = False Then
    Application.Quit
    End If

    End Sub
    [/VBA]

  2. #2
    VBAX Expert Tinbendr's Avatar
    Joined
    Jun 2005
    Location
    North Central Mississippi (The Pines)
    Posts
    993
    Location
    You'll have to save the data before closing the USERFORM.

    You don't indicate what info you want saved, so I'll give a few examples.

    [vba]
    Private Sub Commandbutton2_Click
    'Exit the Form
    sheets(1).range("a5000") = Me.textbox1.value
    sheets(1).range("a5001") = Me.Combobox1.value
    unload Me
    [/vba]
    When you load the userform, in the Userform_Initialize, youll have to add them back in.

    [vba]
    Private Sub Userform_Initialize
    Me.Text1 = sheets(1).range("a5000")
    Me.Combobox1 = sheets(1).range("a5001")
    [/vba]

    David


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •