-
Forms & VBA
Hello all,
I'm currently working on an assignment and the directions are as follows:
"Create a form in MS Access to gather the results of 50 coin flips. Obviously, each coin flip results in either a “head” or “tails”.
Include on this form two buttons. One button, when clicked, will display the percentage of flips which resulted in Heads. You can display that with a message box or a text box on the form. The second button displays a pie chart showing the percentages of heads and tails."
I'm having a lot of trouble with this. So far - I have written a VBA Code for the coin flips function, but don't know what else to do from here.
Here is the code:
Code:
Dim dblRandomNumber As Double
Randomize
dblRandomNumber = Rnd
If dblRandomNumber >= 0.5 Then
Form_Form1.Text1 = "H"
Else
Form_Form1.Text1 = "T"
End If
I don't know where to go from here. Please help!!
-
Follow Up: Additional Directions/Clarification
You are creating a FORM containing enough text boxes for someone to enter the results of 50 coin flips. Thus, the text boxes would contain an "H" or "T" as entered. The flips do not need to be generated randomly, and the form should NOT automatically generate the results of the coin flip.
-
Every Form has a collection of all the Controls on the form.
You can check the Type of each Control.
You can also create your own collection from the Controls Collection using the same check.
You can Loop thru either collection.
For Each
Me
Add
Outside the Form, after it is Instantiated, you can use something like
Code:
With Form
For Each X in .Collection
X.Value = CoinToss 'your function
With