PDA

View Full Version : Exit userform and save changes



Student1000
05-20-2010, 05:38 AM
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):


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

Tinbendr
05-20-2010, 02:20 PM
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.


Private Sub Commandbutton2_Click
'Exit the Form
sheets(1).range("a5000") = Me.textbox1.value
sheets(1).range("a5001") = Me.Combobox1.value
unload Me

When you load the userform, in the Userform_Initialize, youll have to add them back in.


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