Reputation: 2313
UserForm 2 = 36 buttons (btn1 thru btn36) Each button has an image on it. When I click the "ADD" button I would like for three randon images that are on the buttons to show up in UserForm 1 three lables where it says Random Image 1.
Upvotes: 0
Views: 392
Reputation: 27220
To choose a random button image you'll need to use the collection Me.Controls on the form. For example:
Dim cCont As Control
For Each cCont In Me.Controls
'DO STUFF HERE
Next cCont
If you put a watch on the variable cCont, you can see all the properties each control has. First, you will have to filter out the controls that are buttons. You will then have to look at the image property for that button to grab it and set on the second form.
Finally, to introduce a random element, just use the Rand() function. This will return a random number between 0 and 1. If you multiply this by the number of controls in Me.Controls, and round it to an integer, you will get a random control. Just make sure that the control you indexed is a button, and you can use that button's image as one of the random images.
Upvotes: 1