VBAJam
VBAJam

Reputation: 61

Run-time Error 424 Object Required UserForm doesnt exist

I'm attempting to do the things written on this site www.excel-easy.com but when I click the commandbutton (from ActiveX controls) in the worksheet just like what the website instructed, nothing happens. I tried to use a button from form controls, but it says that the error is in this ---> DinnerPlannerUserForm.Show

My Code:

Sub Button2_Click()
    DinnerPlannerUserForm.Show
End Sub

When I used F8, it said the error is here --> Private Sub UserForm_Initialize()

Private Sub UserForm_Initialize()

    'Empty NameTextBox
    NameTextBox.Value = ""

    'Empty PhoneTextBox
    PhoneTextBox.Value = ""

    'Empty CityListBox
    CityListBox.Clear

    'Fill CityListBox
    With CityListBox
        .AddItem "San Francisco"
        .AddItem "Oakland"
        .AddItem "Richmond"
    End With

    'Empty DinnerComboBox
    DinnerComboBox.Clear

    'Fill DinnerComboBox
    With DinnerComboBox
        .AddItem "Italian"
        .AddItem "Chinese"
        .AddItem "Frites and Meat"
    End With

    'Uncheck DataCheckBoxes
    DateCheckBox1.Value = False
    DateCheckBox2.Value = False
    DateCheckBox3.Value = False

    'Set no car as default
    CarOptionButton2.Value = True

    'Empty MoneyTextBox
    MoneyTextBox.Value = ""

    'Set Focus on NameTextBox
    NameTextBox.SetFocus

End Sub

Upvotes: 6

Views: 41691

Answers (7)

Al Blair
Al Blair

Reputation: 1

It was "typo" issues for me - I was using the same DinnerPlannerUserForm guide. Worked once I checked all the (Name) boxes were all exactly the same as the names referred to in the code.

The guide is good, except the element "Show the userform" step, and it could perhaps remind us to double check names are exact. I first used this guide about 6 years ago and it helped me build some incredibly useful forms over the years.

Upvotes: 0

SendETHToThisAddress
SendETHToThisAddress

Reputation: 3704

I had this same issue. I was creating the same form in a few workbooks and using the same variable names. I pasted in my code for UserForm_Initialize. Everything looked good in the code, but I went back and double checked my variable names on the form and realized I had forgotten to name two of the text boxes on my form. My code was trying to assign values to txtMaxLines and txtAmount but I hadn't named them on the form, so to the vba it was like they didn't exist.

I hope this will help someone because if you have the same issue as I did, when it opens up the vba editor it doesn't go to the line where the error is and the error description is not helpful at all.

Upvotes: 1

David
David

Reputation: 31

I was using the same tutorial and solved the problem by changing the Initialize command:

It is given as

Private Sub UserForm_Initialize()

I named my user form (for my own purposes)

StdTimeCalculatorForm

and changing the code to

Private Sub StdTimeCalculatorForm_Initialize()

solved the problem. Hope this helps.

Upvotes: 3

Bart
Bart

Reputation: 81

This error can also occur when you remove or delete a textbox from your form, but forget to remove it from a line in initialization for eg:

Private Sub UserForm_Initialize()
    CommandButton2.Enabled = False
    TextBox4.Enabled = False    'textbox deleted from form
End sub

Upvotes: 8

Ryder88
Ryder88

Reputation: 11

I was able to solve these by changing

Private Sub UserForm_Initialize()

to

Private Sub DinnerPlannerUserForm_Initialize()

See if it works

Upvotes: 1

Stephanie
Stephanie

Reputation: 41

I'm assuming this issue has been resolved, but for anyone just now looking at it. I had this issue and it turned out to be that I had removed a ComboBox from my form, but it was still referenced in the code. Once I removed that section of the code, it worked beautifully.

Upvotes: 4

John Coleman
John Coleman

Reputation: 51998

Hard to tell based on what you have said. But -- the fact that you said using F8 indicated that the error is in Private Sub UserForm_Initialize() suggests that the userform exists and VBA knows how to find it (otherwise its initialize event wouldn't be firing when you click the form button). Hence -- it is one of the lines in the initialize sub which is the culprit. Which line specifically is flagged? I'm guessing that a simple typo in the name of one of the controls (e.g. DinnerComboBox) is the problem.

Upvotes: 1

Related Questions