Reputation: 33
Morning all!
I'm having trouble getting a userfrom to show.
Below is the code I want to use. I declare the Userfrom (oUserform) as a public variable, initialize it and make the changes, then show it.
That's the plan anyway, however I get an error with oUserform.show, saying that the object doesn't support the property or method.
Public oUserform As UserForm
Public iNumberOfRecords As Integer
Public iEndRow As Integer
Sub subIntialize()
Set oUserform = frmbusinessimpact
iEndRow = Sheet1.Cells(1, 1).CurrentRegion.Rows.Count
iNumberOfRecords = iEndRow - 1
Call subPopulateRecordClass(iEndRow)
With oUserform
.TotalRecords = iNumberOfRecords
.CurrentRecord = 1
Call subUpdateUserform
End With
oUserform.Show
End Sub
Any ideas?
Upvotes: 0
Views: 2666
Reputation: 27488
You'll want to declare oUserform
as an instance of frmbusinessimpact
and use the New
keyword.
Public oUserform As frmbusinessimpact
Public iNumberOfRecords As Integer
Public iEndRow As Integer
Sub subIntialize()
Set oUserform = New frmbusinessimpact
iEndRow = Sheet1.Cells(1, 1).CurrentRegion.Rows.Count
iNumberOfRecords = iEndRow - 1
Call subPopulateRecordClass(iEndRow)
With oUserform
.TotalRecords = iNumberOfRecords
.CurrentRecord = 1
Call subUpdateUserform
End With
oUserform.Show
End Sub
The book Professional Excel Development has a good chapter on how, and why, to code userforms this way. I've got a more specific example at http://yoursumbuddy.com/a-flexible-vba-chooser-form/.
Upvotes: 1