Userform_Initialize Only Working Once

Cat129

Board Regular
Joined
Oct 20, 2012
Messages
96
Evening All,

Could someone help me understand what I am doing wrong please.

I am trying to create a user form (my first one)

When I use userform_initialize it works the very first time I run the script. I then close the form to make some changes and next time I run the same script I get ' Run-time error '424' Object Required.

The form is called ScannerInput, so I changed my code to ScannerInput_Initialized but then my preset inputs dont appear. Code below.

Thanks,

Code:
Private Sub UserForm_Initialize()


With DepartmentListBox
    .AddItem "Goods In"
    .AddItem "Machine Shop"
    .AddItem "Quality In"
    .AddItem "Quality Out"
    .AddItem "Goods Out"
End With


NameTextBox.Value = "UserName"


DateTextBox.Value = "Use TODAY()"


TimeTextBox.Value = "Use NOW()"


BarcodeTextBox.Value = "Scan Barcode"


End Sub
 

Excel Facts

Select all contiguous cells
Pressing Ctrl+* (asterisk) will select the "current region" - all contiguous cells in all directions.
How are you closing the form?
 
Upvote 0
To start I used the 'x' in the top right corner.

I then tried

Code:
Private Sub CancelCommandButton_Click()


Unload Me


End Sub

I have tried closing and reopening excel to get it to load with initialize but now I only get the error message mentioned above
 
Upvote 0
I think it was something glitchy going on, as I had to restart for another reason and now it is working as expected. Thank you for your reply, and sorry for wasting your time.

Cat
 
Upvote 0
Although you changed the name of your userform, the declaration for the initialize event should remain as...

Code:
[COLOR=#333333]Private Sub [B]UserForm[/B]_Initialize()[/COLOR]

Otherwise you'll find that the initialize event won't get triggered when the userform is shown.
 
Upvote 0

Forum statistics

Threads
1,215,453
Messages
6,124,918
Members
449,195
Latest member
Stevenciu

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