PDA

View Full Version : Private Sub userform_load()????



ironj32
05-16-2007, 10:06 AM
I cannot get get this code to work. I want info from a hidden sheet to load into the userform upon opening. Any answers?


'------ load data -------------------------------------------
Private Sub frmCREContractForm_load()
On Error Resume Next

Dim ws As Worksheet
Set ws = Worksheets("Saved")

Me.txtUSBManager.Value = ws.Cells(3, 1).Value
Me.txtVendorName.Value = ws.Cells(3, 2).Value
Me.txtContractStartDate.Value = ws.Cells(3, 3).Value
Me.txtExpectedTerm.Value = ws.Cells(3, 4).Value
Me.txtExpectedValue.Value = ws.Cells(3, 5).Value
Me.cboSelectOne.Value = ws.Cells(3, 6).Value
..........
..........
End Sub

Norie
05-16-2007, 10:11 AM
Change frmCREContractForm to UserForm.

lucas
05-16-2007, 10:14 AM
Looks like a couple of things....first it has to be the click event of the command button...._Click second you had your txtbox and cellvalues reversed in order...something like:
Private Sub frmCREContractForm_load_Click()
On Error Resume Next

Dim ws As Worksheet
Set ws = Worksheets("Saved")
ws.Cells(3, 1).Value = Me.txtUSBManager.Value
End Sub

lucas
05-16-2007, 10:15 AM
As Norie points out...if your not using a commandbutton and you want this to happen when the form loads...

lucas
05-16-2007, 10:22 AM
I'm the one who had it backwards....Norie has it correct and your original code should work if you follow Nories advice....sorry

ironj32
05-16-2007, 10:23 AM
This doesn't work.


'------ load data -------------------------------------------
Private Sub Userform_load()
On Error Resume Next
Dim ws As Worksheet
Set ws = Worksheets("Saved")
Me.txtUSBManager.Value = ws.Cells(3, 1).Value
Me.txtVendorName.Value = ws.Cells(3, 2).Value
Me.txtContractStartDate.Value = ws.Cells(3, 3).Value
Me.txtExpectedTerm.Value = ws.Cells(3, 4).Value

lucas
05-16-2007, 10:29 AM
Private Sub UserForm_Initialize()
On Error Resume Next
Dim ws As Worksheet
Set ws = Worksheets("Saved")
Me.txtUSBManager.Value = ws.Cells(3, 1).Value
Me.txtVendorName.Value = ws.Cells(3, 2).Value
Me.txtContractStartDate.Value = ws.Cells(3, 3).Value
Me.txtExpectedTerm.Value = ws.Cells(3, 4).Value
End Sub

lucas
05-16-2007, 10:30 AM
don't change the first line to match the name of your userform....just put the code in the userform code module as it is.

ironj32
05-16-2007, 10:36 AM
yeah i put userform_activate() and that worked. _initialize() also works.
Thanks guys!

Norie
05-16-2007, 11:58 AM
Oops!:oops:

Should have caught that, there is no Load event for a userform in Excel.

Must have been in Access mode, honest.:)