Page 2 of 2 FirstFirst 12
Results 16 to 21 of 21
  1. #16
    isladogs's Avatar
    isladogs is offline Access MVP / VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    6,204
    To be fair, the OP did refer to controls 11, 21, 31, 41, 51. Etc.
    It was me trying to simplify coding who suggested using 1-25.

    As micron rightly points out that won't work.


    However as long as the 25 checkboxes are uniquely identifiable, the code will work either in the way I originally suggested or using a modified function
    Colin Riddington, Access MVP, Website, email
    The more I learn, the more I know I don't know. When I know I don't know, I keep quiet!

  2. #17
    Micron is offline Very Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    13,423
    And I am not sure why you say the value is stored, I assumed Paul's check-boxes are unbound controls.
    my bolded text is copied from post 7 where OP says the value is stored.

    EDIT
    So after reviewing, all one needs is to concatenate the 2 values as a string and find the checkbox whose name matches that string and set that one to True and the rest to false in a loop?
    Last edited by Micron; 03-09-2018 at 04:11 PM. Reason: clarification

  3. #18
    Gicu's Avatar
    Gicu is offline VIP
    Windows 8 Access 2013
    Join Date
    Jul 2015
    Location
    Kelowna, BC, Canada
    Posts
    4,250
    Hi Micron, yes, that was my intent with the loop. I believe you need to reset them somehow in a loop. So Colin's modified loop would work in my opinion.


    Colin, with your original code from post #8 wouldn't they accumulate as you change the values of the combo boxes (meaning you would be turning them visible one by one but not resetting the older ones)?

    Cheers,
    Vlad

  4. #19
    isladogs's Avatar
    isladogs is offline Access MVP / VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    6,204
    Colin, with your original code from post #8 wouldn't they accumulate as you change the values of the combo boxes (meaning you would be turning them visible one by one but not resetting the older ones)?
    In that post I wrote
    Code:
    Hide all of them by default
    Good point. Perhaps not as clear as I meant it to be, but I also meant reset all to false when the combos were changed.
    Colin Riddington, Access MVP, Website, email
    The more I learn, the more I know I don't know. When I know I don't know, I keep quiet!

  5. #20
    Gicu's Avatar
    Gicu is offline VIP
    Windows 8 Access 2013
    Join Date
    Jul 2015
    Location
    Kelowna, BC, Canada
    Posts
    4,250
    Hi all, after all these discussions I think the code should be modified as follows (the function assumes there are no other check-boxes on the form; if they are they should be excluded by an additional if statement) :

    Private Function DealWithCheckboxes(sProd as string)
    Dim ctl as control

    For each ctl in Me.Controls
    if ctl.controltype=acCheckBox then
    If ctl.Name = "chk" & sProd then
    ctl.Value=true
    ctl.Visible=true
    Else
    ctl.Value=False
    ctl.Visible=False
    End if
    end if
    Next ctl

    End function

  6. #21
    Micron is offline Very Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    13,423
    Looks good, but I think I'd put that behind a button click. So, user chooses a value in each combo, and rather than run the code on either of the 2 combos' AfterUpdate event (since you can't guarantee which one they'll choose from first), require a button click to calculate. That way, they can also refrain from calculating should they make the wrong choice in one or the other because they can change their entry. So assuming 1st combo is cmb1 and the other is cmb2 and the added button is named cmdCalculate:
    Code:
    Private Sub cmdCalculate_Click()
    Dim ctl As Control
    Dim strProd As String
    
    If IsNull(Me.cmb1) Or IsNull(Me.cmb2) Then
     msgbox "A value must be chosen from each list"
     Exit Sub
    End If
    
    strProd = cmb1 & cmb2
    
    For each ctl in Me.Controls
     If ctl.Controltype = acCheckBox Then
      If ctl.Name = "chk" & strProd Then
       ctl.Value = True
       ctl.Visible = True
      Else
       ctl.Value = False
       ctl.Visible = False
      End If
     End If
    Next ctl
    
    End Sub
    I had a bit to coerce the concatenated numeric values into a string (Cstr) just in case but I removed it - likely not necessary. Nor does that code ensure the combos don't contain an empty string, which shouldn't ever be needed. Also, I don't think this was covered, but the limit to list property should be true if using a value list.

Page 2 of 2 FirstFirst 12
Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 5
    Last Post: 09-06-2017, 08:34 AM
  2. Replies: 3
    Last Post: 02-20-2017, 08:27 AM
  3. Replies: 2
    Last Post: 08-21-2014, 08:36 AM
  4. Replies: 5
    Last Post: 07-24-2014, 07:54 AM
  5. Replies: 1
    Last Post: 05-29-2013, 04:01 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums