Loading values into a form on open.

  • Thread starter Thread starter J. Vandenberg
  • Start date Start date
J

J. Vandenberg

At the moment I have a form that opens with a button click. It's not a
Private Sub because the button I am using is an autoshape which just
has the macro assigned to it.

Sub newdayBtn_Click()
Application.ScreenUpdating = False
dailyFrm.Show 0 // Tried running it non modal too.

// Then I want it to load values on open into text boxes from cells in
a sheet.

Sheets("Data").Activate
dpr1 = Cells(25, 3)
dpr2 = Cells(25, 4)

// The dpr's are text box names. The thing is, unless I add another
action, ie. tab change, or form click, it will not load the values.

// I thought maybe a repaint would make them show up, but nada. I am
not sure how to initialize the form without a seperate routine, is
there a simple way to make this happen in one click?

Thanks,
-Joel
 
You must load the values in a event in the userform
Only load the Userform when you click the autoshape

Use this event in the Userform module

Private Sub UserForm_Initialize()
Me.TextBox1.Value = Sheets("Sheet1").Cells(25, 3).Value
End Sub
 
Sub newdayBtn_Click()
' Application.ScreenUpdating = False
dailyFrm.Load
With Sheets("Data")
dailyFrm.dpr1 = .Cells(25, 3).Value
dailyFrm.dpr2 = .Cells(25, 4).Value
End With
dailyFrm.Show 0
End Sub
 
Back
Top