Control UserForm through procedure iin module

Stevenn

Active Member
Joined
Feb 8, 2012
Messages
259
I have a module with a procedure called Upload() and a UserForm where the user should insert both username and password and click the command button.

I want to control the UserForm through the procedure Upload() instead of using cmdUpload_Click and such. Something like

Code:
Public Sub Upload()
    With frmUpload
        .txtUsername = VBA.Environ("Username")
        .txtPassword.SetFocus
        .Show
    End With
End Sub

but how can I check if the user had clicked the command button and eventually make a progress bar in the UserForm? I hope my problem is clearly explained ;)
 

Excel Facts

Why does 9 mean SUM in SUBTOTAL?
It is because Sum is the 9th alphabetically in Average, Count, CountA, Max, Min, Product, StDev.S, StDev.P, Sum, VAR.S, VAR.P.
You'd use Custom Events and a class, however I'm not really sure why you'd want to do this.

Can you give us a little background as to why you need to do this?
 
Upvote 0
You'd use Custom Events and a class, however I'm not really sure why you'd want to do this.

Can you give us a little background as to why you need to do this?

I just want to combine the module which activates the UserForm and the module which does the upload-thing. I thought there were some kind of functions which could do it for me (like Load or something), but if it's more difficult than doing the upload-thing in the UserForm-procedures, then I will continue doing it that way. Would it be preferable to do the upload-thing in the procedure cmdUpload_Click()?
 
Upvote 0
You could do something like the below but it's really horrible design. If you (or someone else) comes back to it in 12 months time, you would have to hunt to follow the code which would be a massive pain. Try to keep your code as close to the things that trigger it as possible, it makes maintenance easier and much more logical.

In your Form:
Rich (BB code):
Private Sub cmdUpload_Click()
btnClicked
End Sub

In your module
Rich (BB code):
Public Sub btnClicked()
'Do Something....
End Sub

It's not a good approach though - coming back to this if it were a large project would be problematic as you would have to find the btnClicked sub. Just put the upload code in the upload button, it's logical and easy to track :)
 
Upvote 0
What is the purpose of the userform and what do you want to 'control' on it?

Why not just call the upload code when a command button is clicked?
Code:
Private Sub CommandButton1_ Click()
    Call UploadSub
End Sub
 
Last edited:
Upvote 0

Forum statistics

Threads
1,214,785
Messages
6,121,543
Members
449,038
Latest member
Guest1337

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