Userform not initializing or activating

Godwin117

Board Regular
Joined
Dec 19, 2019
Messages
68
Office Version
  1. 365
  2. 2019
Platform
  1. Windows
I am stuck and can't seem to find the answer or overlooked the answer. Below is the code for my module to show the userform. This part works correctly.
VBA Code:
Sub Log_Hours()

UserForm1.Show

End Sub

The Userform loads properly, until I change the Userform1 to Userform, not sure why. Then I am getting a Automation error. Below is that code.

VBA Code:
Private Sub UserForm1_Initialize()

Me.ComboBox1.List = WorksheetFunction.Transpose(Worksheets("Data Validation").Range("C2", Worksheets("Data Validation").Range("C" & Rows.Count).End(xlUp)))
Me.TextBox1.Value = "mm-dd-yyyy"

End Sub

Any help on this would be greatly appreciated.
 

Excel Facts

Does the VLOOKUP table have to be sorted?
No! when you are using an exact match, the VLOOKUP table can be in any order. Best-selling items at the top is actually the best.
... when you say "Change" please clarify; Change the name? Change the code? Change the name of the Sub, Change the name of the userform, in the VBA properties window?
 
Upvote 0
The Userform loads properly, until I change the Userform1 to Userform, not sure why
You should never change the name of any event code. It must be kept as Private Sub UserForm_Initialize() regardless of the name of the userform.
 
Upvote 0
... when you say "Change" please clarify; Change the name? Change the code? Change the name of the Sub, Change the name of the userform, in the VBA properties window?
When I change Private Sub Userform1_Initialize() to Private Sub Userform_Initialize() it gives me Automation Error Exception Occurred. I'm unsure why it is doing that.
 
Upvote 0
As already mooted; never change the name of the event code-holders (these are built-in holders which their respective objects refer to).
When you insert a new UserForm, and wish to put some code into its Initialize event-holder, this is what you see:
VBA Code:
Private Sub UserForm_Initialize()

End Sub
It doesn't matter if you have 10 or 100 UserForms, their _initialize event holders will all look identical, and must remain the same.

You say your code fails when you change the name TO
VBA Code:
Private Sub UserForm_Initialize()
... but it should be the other way around - the issue should occur, if you change the event name FROM the original.
If changing it back to the original still gives you issues, I'd be inclined to delete that block of code altogether - including the:
VBA Code:
Private Sub UserForm_Initialize()

End Sub
(you could save the other lines in there, before doing so), then select the userform in the VBA browser again, right-click "View code" then re-select the _Initialize event from the top drop-down, on the right, and start again (paste your copied code back in, if required).
As your having difficulty with this event, I'd be inclined to carry this out on a COPY of your work first - just to be sure all's well.

HTH
 
Upvote 0
the issue should occur, if you change the event name FROM the original.
You won't get an issue if the name of the event is changed, it simply won't run.

@Godwin117 In the VB Editor, click on tools, Options, General & then select the option "Break in Class Module" & click OK.
Then try running your code again using the Private Sub UserForm_Initialize() sub. What error do you get & what line is highlighted.
 
Upvote 0
You should never change the name of any event code. It must be kept as Private Sub UserForm_Initialize() regardless of the name of the userform.

You won't get an issue if the name of the vent is changed, it simply won't run.

@Godwin117 In the VB Editor, click on tools, Options, General & then select the option "Break in Class Module" & click OK.
Then try running your code again using the Private Sub UserForm_Initialize() sub. What error do you get & what line is highlighted.
I'm getting Automation error exception occurred. It previously worked fine then when I saved an exited it started giving me this error.
 
Upvote 0
Which line is highlighted if you click debug?
 
Upvote 0
Which line is highlighted if you click debug?
The first line after Userform_Initialize.

VBA Code:
Private Sub UserForm_Initialize()

[COLOR=rgb(226, 80, 65)]Me.ComboBox1.List = WorksheetFunction.Transpose(Worksheets("Data Validation").Range("C2", Worksheets("Data Validation").Range("C" & Rows.Count).End(xlUp)))[/COLOR]
Me.TextBox1.Value = "mm-dd-yyyy"

End Sub
 
Upvote 0
Check in the properties of the combo & make sure that the rowsource property is empty.
 
Upvote 0

Forum statistics

Threads
1,214,387
Messages
6,119,222
Members
448,877
Latest member
gb24

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