Results 1 to 5 of 5
  1. #1
    2 Star Lounger
    Join Date
    Apr 2015
    Posts
    153
    Thanks
    70
    Thanked 0 Times in 0 Posts

    Talking Working with a form for quizzes

    Hi Experts,

    I've attached a file I am using to learn VBA. I have some code but having trouble finding everything to complete the project.

    I need code to:

    1. Select the row that user enters in the combo box

    2. If user answers the question correctly a label appears: Correct

    3. If user answers the question incorrectly a label appears: Incorrect

    Note: labels are on the form, stacked on top of each other.

    Thanks for any help provided!
    Attached Files Attached Files

  2. #2
    Super Moderator RetiredGeek's Avatar
    Join Date
    Mar 2004
    Location
    Manning, South Carolina
    Posts
    9,436
    Thanks
    372
    Thanked 1,457 Times in 1,326 Posts
    E.N.,

    Ok, here's what I did:

    1. Change Answers from T/F to True/False (makes testing easier later)
    2. Delete lblIncorrect
    3. Delete the True/False checkboxes.
    4. Create True/False radio buttons in a frame. This is so you can only select one.
    5. In the Click events for the buttons change the Caption of the lblCorrect (remaining label)

      Code:
      Private Sub obtnFalse_Click()
        
        Dim lCurQRow As Long
        
        lCurQRow = WorksheetFunction.Match(CboReference.Value, Range("RefList")) + 1
        LblCorrect.Caption = IIf(Me.obtnFalse.Value <> Cells(lCurQRow, 5), "Correct", "Incorrect")
      
      End Sub
      
      Private Sub obtnTrue_Click()
        
        Dim lCurQRow As Long
        
        lCurQRow = WorksheetFunction.Match(CboReference.Value, Range("RefList")) + 1
        LblCorrect.Caption = IIf(Me.obtnTrue.Value = Cells(lCurQRow, 5), "Correct", "Incorrect")
        
      End Sub
    6. In the click event for the Reference combobox clear the lblCorrect caption.
      Code:
      Private Sub CboReference_Click()
          With Me
              .Txt1.Value = Sheet1.Cells(.CboReference.ListIndex + 2, 6)
              .Txt2.Value = Sheet1.Cells(.CboReference.ListIndex + 2, 7)
              .Txt3.Value = Sheet1.Cells(.CboReference.ListIndex + 2, 8)
              .Txt4.Value = Sheet1.Cells(.CboReference.ListIndex + 2, 9)
              .Txt5.Value = Sheet1.Cells(.CboReference.ListIndex + 2, 10)
              .LblCorrect = ""
          End With
          
      End Sub


    Test File: WSQuiz-RGV1.xlsm

    HTH
    May the Forces of good computing be with you!

    RG

    PowerShell & VBA Rule!

    My Systems: Desktop Specs
    Laptop Specs

  3. The Following User Says Thank You to RetiredGeek For This Useful Post:

    Excelnewbie (2015-12-02)

  4. #3
    Gold Lounger Maudibe's Avatar
    Join Date
    Aug 2010
    Location
    Pa, USA
    Posts
    2,640
    Thanks
    115
    Thanked 651 Times in 593 Posts
    Excel,

    for question 1, here is a possible solution

    Code:
    'Code fills textboxes with row of code that is in the combo box
    Private Sub CboReference_Click()
    Dim row As Integer
    With Worksheets("Sheet1")
    Select Case CboReference.Value
        Case "A"
            .Rows(2).Select: row = 2
        Case "B"
            .Rows(3).Select: row = 3
        Case "C"
            .Rows(4).Select: row = 4
    End Select
            Txt1.Value = .Cells(row, 6)
            Txt2.Value = .Cells(row, 7)
            Txt3.Value = .Cells(row, 8)
            Txt4.Value = .Cells(row, 9)
            Txt5.Value = .Cells(row, 10)
    End With
    End Sub

  5. #4
    Gold Lounger Maudibe's Avatar
    Join Date
    Aug 2010
    Location
    Pa, USA
    Posts
    2,640
    Thanks
    115
    Thanked 651 Times in 593 Posts
    Excel,

    On your form you may want to consider using grouped option buttons instead of checkboxes. It will save you a lot of time from having to write code to prevent more than one checkbox being ticked at a time in a grouping (type, difficulty, T/F).

    HTH,
    Maud

  6. The Following User Says Thank You to Maudibe For This Useful Post:

    Excelnewbie (2015-12-02)

  7. #5
    2 Star Lounger
    Join Date
    Apr 2015
    Posts
    153
    Thanks
    70
    Thanked 0 Times in 0 Posts
    RG & Maud-

    Thanks for your expertise, help, and kindness. I am working on the file with the code and ideas you provided.

Posting Permissions

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