Results 1 to 5 of 5
  1. #1
    Silver Lounger
    Join Date
    Jan 2002
    Posts
    1,615
    Thanks
    0
    Thanked 1 Time in 1 Post

    Check boxes on a form (XP)

    Hi,

    I am trying to create form that will give the user the option of selecting one or more options at a time. In this instance, the when the box is checked, a corresponding report will open when the user clicks a control button. The goal is to allow the user to select one report at a time or multiple reports. I simply do not "get" how to make check boxes or option boxes to work. What would be the best approach and where do I start. I've tried using info in Access Help as well as the Access Bible and I'm missing something. I'm determined not to give up and find a work around like I have in the past!
    Thanks,
    Leesha

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Check boxes on a form (XP)

    You should use check boxes for this, not option buttons aka radio buttons. Option buttons are meant to provide a mutually exclusive choice: if the user selects one, all others are deselected. Check boxes are meant to provide multiple selection.

    You will have to test each check box in turn when the command button is clicked. Code could look like this:

    Private Sub cmdOpenReports_Click()

    If Me.chkReport1 = True Then
    DoCmd.OpenReport "rptFirstReport", acViewPreview
    End If

    If Me.chkReport2 = True Then
    DoCmd.OpenReport "rptSecondReport", acViewPreview
    End If

    ...

    End Sub

    If you actually name the check boxes chkReport1, chkReport2 etc., you can also use a loop:

    Private Sub cmdOpenReports_Click()

    Const intNumberOfReports = 10
    Dim strReportNames(1 To intNumberOfReports) As String
    Dim i As Integer

    strReportNames(1) = "rptFirstReport"
    strReportNames(2) = "rptSecondReport"
    ...

    For i = 1 To intNumberOfReports
    If Me.Controls("chkReport" & i) = True Then
    DoCmd.OpenReport strReportNames(i), acViewPreview
    End If
    End If

    End Sub

    Note 1: You could store the report names in a table instead of using an array.
    Note 2: Do not put the check boxes in an option frame. That will make them mutually exclusive.
    Note 3: You could also use a multi-select list box instead of a series of check boxes.

  3. #3
    Silver Lounger
    Join Date
    Jan 2002
    Posts
    1,615
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Check boxes on a form (XP)

    Hi Hans!

    As always you've made what all the other reading I've done seem acheivable! You should write the Bible book! I think I'll play with option 1 or 3. The "loop" piece seens a bit over my head! I've never stored report names in a table! What a concept for keeping them straight especially when there are so many with similar names. Of course that leads to my next question.....................if I store them in a table, could show me some sample code as to how I'd reference them??

    Thanks so much,
    Leesha

  4. #4
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Check boxes on a form (XP)

    Place a list box on your form.
    Name it lbxReportNames.
    Set its Row Source to the name of the table containing the report names.
    Set its Multi Select property to Simple (users can click to select or deselect additional items) or to Extended (users can select a contiguous range by Shift+click, or select/deselect individual items by Ctrl+click, the same way you can select files in Windows Explorer.)

    The On Click code for the command button would look like this:

    Private Sub cmdOpenReports_Click()
    Dim varSelected As Variant
    For Each varSelected In Me.lbxReports.ItemsSelected
    DoCmd.OpenReport Me.lbxReports.ItemData(varSelected), acViewPreview
    Next varSelected
    End Sub

  5. #5
    Silver Lounger
    Join Date
    Jan 2002
    Posts
    1,615
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Check boxes on a form (XP)

    Thanks Hans! This is such and exciting option!

    Leesha

Posting Permissions

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