User Form Initialize Error

BDubbs

New Member
Joined
Jul 15, 2016
Messages
8
Hello,
I have an Excel workbook with two different user forms. I want to use an Initialize event to populate some combo boxes. On the first user form, everything works great. When I try to use the second one, I get "Run-Time Error 424 Object Required". The debugger highlights the line in the code that calls the user form. I have a feeling the error is somewhere in the Initialize code, because if I remove the initialize code, the user form runs fine.

The code for both forms is almost identical. Only the names are changing. Please help.

Code:
Private Sub UserForm_Initialize()
    cmbPartnum.SetFocus
    cmbPartnum.List = Array("24921", "24343", "24354", "25925", "11913", "11914-001", "21992-001", "15695", "16550", "50885")
    cbmOperator.List = Array("AP", "FN", "LM", "MW", "RB", "JC", "MM")
    cmbLaser.List = Array("EGYNGR")
End Sub

Code:
Sub Button2_Click()
    ufLaserEntry.Show
End Sub
 

Excel Facts

How to show all formulas in Excel?
Press Ctrl+` to show all formulas. Press it again to toggle back to numbers. The grave accent is often under the tilde on US keyboards.
Have you tried stepping through the code in the Initialize event?

You can do that by simply placing the cursor anywhere in that sub and pressing F8.
 
Upvote 0
If the control names are the same on each form, using the Me keyword to both code modules would help Excel keep things sorted

Code:
Private Sub UserForm_Initialize()
    With Me
        .cmbPartnum.SetFocus
        .cmbPartnum.List = Array("24921", "24343", "24354", "25925", "11913", "11914-001", "21992-001", "15695", "16550", "50885")
        .cbmOperator.List = Array("AP", "FN", "LM", "MW", "RB", "JC", "MM")
        .cmbLaser.List = Array("EGYNGR")
    End With
End Sub
 
Upvote 0
Mike,

I added the with me keyword and nothing changed. Then I added the periods and i got "Compile Error - Method or Data Member not found" and the "Private Sub UserForm_Initialize()" line got highlighted.
 
Upvote 0
Hello,
Rich (BB code):
Private Sub UserForm_Initialize()
    cmbPartnum.SetFocus
    cmbPartnum.List = Array("24921", "24343", "24354", "25925", "11913", "11914-001", "21992-001", "15695", "16550", "50885")
    cbmOperator.List = Array("AP", "FN", "LM", "MW", "RB", "JC", "MM")
    cmbLaser.List = Array("EGYNGR")
End Sub

Are you sure that's not just a misspell in the prefix?
 
Upvote 0
That's was it! Thank you all! I went over that code 100 times and didn't see the spelling error.
 
Upvote 0

Forum statistics

Threads
1,215,785
Messages
6,126,887
Members
449,347
Latest member
Macro_learner

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top