UserForm_Initialize? How to update.

  • Thread starter Thread starter Jelso
  • Start date Start date
J

Jelso

Question: If I use UserForm_Initialize when calling up a form with
text boxes, the text boxes won't update if their source cells change.

Is there some other word/commmand I should use instead of "Initialize"
to have the text boxes update with new data? Or is the problem
elsewhere?

Thanks..SJ

------------------------------------
Private Sub UserForm_Initialize()

Title.Text = Range("C1").Value

SAMTitle.Text = Range("E3").Value
SAM1.Text = Range("E4").Value
SAM2.Text = Range("E5").Value
-----------------------------------
 
Jelso,
The form should open with the values from the cells in the textboxes.
Are you changing the cell value after you initialize the form?
If so, after you've changed the cell values try (in a Sub):
Myuserform.repaint.

If that doesn't do it then just get the values again
Private Sub DoSomething_click()

'change the values in the cells
Range("C1").Value = Range("C1").Value +3
Range("E3").Value = Range("E3").Value*3
Range("E4").Value = Range("E4").Value -3
Range("E5").Value = Range("C1").Value + Range("E3").Value +Range("E4").Value

'reset the textboxes
Title.Text = Range("C1").Value
SAMTitle.Text = Range("E3").Value
SAM1.Text = Range("E4").Value
SAM2.Text = Range("E5").Value

End Sub

HTH
Henry
 
Settting the textbox's ControlSource creates a link between the textbox and
the cell. It's read/write in both directions. Changes made in the cell are
passed to the textbox and changes made in the textbox are passed to the
cell.

Private Sub Userform_initialize()
Title.ControlSource = "Sheet1!C1"
SamTitle.ControlSource = "Sheet1!E3"
Sam1.ControlSource = "Sheet1!E4"
Sam2.ControlSource = "Sheet1!E5"
End Sub

or to simply link the controls to the sheet that is active when the form is
shown, remove the sheet designations:

Private Sub Userform_Initialize()
Title.ControlSource = "C1"
SamTitle.ControlSource = "E3"
Sam1.ControlSource = "E4"
Sam2.ControlSource = "E5"
End Sub

In addition, setting ControlSource with VBA code is temporary, so when the
form is unloaded the link is broken. To create a permanent link, set the
ControlSource manually in the VBE.
 
Back
Top