0

I am following the exact steps on creating userform on this website http://www.excel-easy.com/vba/userform.html. I followed all the steps but I can't make it work.

Please see the image for the error. Excel Error

When I pasted this code.

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

this code will have error

Private Sub CommandButton1_Click()

DinnerPlannerUserForm.Show

End Sub

Please see the website first.

3
  • Did you rename the userform to "DinnerPlannerUserForm"? Commented Dec 20, 2016 at 5:44
  • yes. I renamed userform Commented Dec 20, 2016 at 5:46
  • 1
    where are yoiu brought to if you click "Debug" in the error message box? Commented Dec 20, 2016 at 7:12

2 Answers 2

5

One of your controls is not named correctly. Adding Option Explicit to the top of your code modules will usually allow you to catch this type of error early.

enter image description here

Sign up to request clarification or add additional context in comments.

4 Comments

@RexDarwin if you can link the workbook to me I'll debug it for you. You'll need to use a service like Google Docs, Google Drive, FileHippo, DropBox..etc.
Sorry I tried again and I fixed now theres a problem in CarOptionButton :) thank you so much
@BruceWayne I use ScreenToGif. If the file is over SO's 2MB upload limit, I use GifGifs to reduce the file size.
1

It seems that either:

  • you did not rename the UserForm1 to DinnerPlannerUserForm, or
  • you did not rename one of the controls that is mentioned in your Initialize code, or
  • you have never made a call like
    Set MyDinnerPlanner = New DinnerPlannerUserForm
    (variables that refer to objects start as Null; they need to be Set to a New instance at some point before you can use them.)

If you click on the "Object required" error dialog's "Debug" command button, the VBA IDE will take you to a line of code. That line of code will probably have a statement of the form
<ObjectInstanceName>.<MethodName>(<parameters>) or
<ObjectInstanceName>.<PropertyName> = <Value>.
The "Object required" error is telling you that either VBA does not recognize the <ObjectInstanceName> or <ObjectInstanceName> Is Null.

4 Comments

I renamed the UserForm1 to DinnerPlannerUserForm
Where did you rename it? Which property did you change?
I suggest you follow the guide up to the "Show the Userform" part (complete that part). Don't put any other code in. To find your issue you need to simplify the code.
I renamed it in the properties

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.