Consulting

Results 1 to 3 of 3

Thread: Forms & VBA

  1. #1

    Exclamation 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:

    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!!

  2. #2
    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.

  3. #3
    Moderator VBAX Sage SamT's Avatar
    Joined
    Oct 2006
    Location
    Near Columbia
    Posts
    7,814
    Location
    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
    With Form
    For Each X in .Collection
    X.Value = CoinToss 'your function
    With
    Last edited by SamT; 12-11-2013 at 04:16 PM.
    I expect the student to do their homework and find all the errrors I leeve in.


    Please take the time to read the Forum FAQ

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •