Results 1 to 2 of 2
  1. #1
    crowegreg is offline Competent Performer
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Posts
    398

    Collection control within a form

    I have a form with many checkboxes for the user to select. Each checkbox has a label associated with it. I'm using the following code to determine which checkboxes have been selected:



    For Each ctrl In Me.Controls
    If ctrl.ControlType = acCheckBox Then
    If ctrl.Value = True Then


    What I'm needing is to assign the label that is associated with the checkbox to a variable.

    Here's the code I was using to assign the name of the checkbox to the variable, but I need the label instead.
    strcheckboxname = ctrl.Name

  2. #2
    ajetrumpet is offline VIP
    Windows Vista Access 2007
    Join Date
    Mar 2010
    Location
    N/A
    Posts
    2,694
    all controls have different names.

    you would benefit a lot more by naming your checkboxes sequentially and naming the associated labels similar to that, perhaps preceeded with an "L" or something. for instance "checkbox1" and "Lcheckbox1". and so it becomes a piece of cake to assign your label name to a variable.

    your code then becomes this:

    Code:
    for each ctl in me.controls
       if ctl.controltype = accheckbox then
          if ctl.value = -1 then
             strcheckboxname = "L" & ctl.name
          end if
       end if
    next ctl
    hence, a simple loop.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 1
    Last Post: 05-18-2011, 07:23 AM
  2. Collection function
    By ATLANTA in forum Programming
    Replies: 2
    Last Post: 04-17-2011, 04:11 PM
  3. Replies: 1
    Last Post: 03-28-2011, 02:34 PM
  4. Replies: 1
    Last Post: 03-24-2011, 07:25 PM
  5. Button Collection
    By pkstormy in forum Code Repository
    Replies: 0
    Last Post: 08-30-2010, 10:21 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