Userform Function Call works in Module2 but not Module1

hotabae

Board Regular
Joined
Apr 18, 2018
Messages
167
Hello!

I have an option button collection which monitors changes. When a new option button is selected, I want to pass the .Caption of that button into a userform update.

Ultimately, the code in question ends up looking like this:

Code:
Sub Update(caption As String)
UserForm1.updateButton(caption)
End Sub

This sub is in Module2, and I have updateButton(caption As String) located within the UserForm1 code.


At this point it works just fine, but when I move the above code from Module2 to Module1, I start getting a compile error, and the "Auto List Members" functionality stops working.

It is almost like Excel can't find UserForm1 from within Module1.

Does anyone have any idea why this is happening?


Thanks!
 
Last edited:

Excel Facts

Pivot Table Drill Down
Double-click any number in a pivot table to create a new report showing all detail rows that make up that number
Hi,

your userform code

Rich (BB code):
Sub updateButton(caption As String)


End Sub

have you named a control on the userform with the same name? if so, rename either the control or the Sub.
Also, have you declared your sub as Private? if so, change the Private declaration.

Dave
 
Upvote 0
have you named a control on the userform with the same name?

Dave

I do not have a control with the same name. That did get me thinking though, and I managed to figure it out.

Somehow I named my form using the same name as a pre-existing Sub that was in Module1.

Code:
UserForm1.updateButton

was trying to call

Code:
Sub UserForm1()

rather than using the Userform's Code

I have renamed the Sub, and it seems to be working just fine now.

Thanks!
 
Upvote 0

Forum statistics

Threads
1,214,644
Messages
6,120,709
Members
448,983
Latest member
Joaquim_Baptista

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