CheckBox does not save value

  • Thread starter Thread starter Tdp
  • Start date Start date
T

Tdp

I have the following code
Private Sub CheckBox1_Click()
If Me.CheckBox1.Value = True Then
Me.TextBox10.Value = Worksheets("Sheet4").Range("E9")
Else
Me.TextBox10.Value = 0
End If
End Sub

The problem I am having is that when I close the UserForm, the values in the
textbox do not save. It seems to default to random number, in this case 74!!??

Can any one hepl?
 
So why close the form. Just hide it...

userform1.hide
or
me.hide
 
Spoke too soon.
Iv added a bitton to hide the form, but I close the folder and open it again
it does'nt save the values. Still reverts to the value of 74?
 
Hi,

If you weren't closing the file you could store the value by defining a
global variable, which would survive until you closed the spreadsheet.
However, the easiest way if you are going to close the file is to store the
value in a cell in the spreadsheet:

Sheet1!A1=Me.TextBox10

(don't need the Value argument)

Now to get that value back into the textbox add the following code to the
user form:

Private Sub UserForm_Initialize()
Me.TextBox10 = Sheets("Sheet1").Range("A1")
End Sub

A recommendation - give your user form controls names such as txtDate.
 
Thanks Shane,
I worked out now. Did something the same as you but my codes are alittle
longer but does the job.
I'v used:
Me.TextBox10.Value = Worksheets("Sheet4").Range("E19").Value

Worksheets("Sheet4").Range("E19") = TextBox10.Value
Seems to work ok!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top