Results 1 to 5 of 5
  1. #1
    HansBades is offline Advanced Beginner
    Windows 10 Office 365
    Join Date
    Dec 2021
    Posts
    85

    Looping through checkboxes

    I have some code where I am looping through checkboxes on a form where each checkbox name represents a field name from another form. If the checkbox is checked, the code is designed to hide that field in the other form. This works fine if I state the name of the control explicitly. But when I loop through each checkbox is designated as the current "ctl" or "ctl.name", I get a syntax error. I think this is perhaps because the ctl it is supposed to hide is in another form. Is there any way to get around this? Thanks!

    Dim ctl As Control
    For Each ctl In Me.Controls
    If ctl.ControlType = acCheckBox Then
    If ctl.Value = True Then
    Forms!SKUWorkOrder_SubformWODetails.Form.ctl.Name.ColumnHidden = True
    End If


    End If
    Next ctl

  2. #2
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,525
    bad syntax, it may be:

    Forms!SKUWorkOrder_SubformWODetails.Form.contols(ctl.Name).ColumnHidden = True

  3. #3
    Micron is online now Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,801
    I'd say that the ctl object doesn't exist on the other form so you can't refer to it as an object. First see if you got the form reference right
    Msgbox Forms!SKUWorkOrder_SubformWODetails.Form.name

    If that looks good, then try assigning ctl.Name to a variable and use that as in
    Forms!SKUWorkOrder_SubformWODetails.Form.Controls(strName).ColumnHidden = True
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  4. #4
    moke123's Avatar
    moke123 is offline Me.Dirty=True
    Windows 11 Office 365
    Join Date
    Oct 2012
    Location
    Ma.
    Posts
    1,654
    .columnhidden applies to datasheets not controls. Controls have a visible property.
    If this helped, please click the star * at the bottom left and add to my reputation- Thanks

  5. #5
    Micron is online now Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,801
    I took it that this is about a datasheet form? You can hide a datasheet column by referring to the control name. Try this in your immediate window on an open datasheet form:

    Forms!FormNameHere.txtBoxNameHere.ColumnHidden = True

    EDIT - from documentation
    The ColumnHidden property applies to all fields in Datasheet view and to form controls when the form is in Datasheet view.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

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

Similar Threads

  1. Looping Is Incorrect
    By DMT Dave in forum Access
    Replies: 14
    Last Post: 07-11-2021, 07:45 PM
  2. Looping a running sum
    By dmvpia in forum Reports
    Replies: 4
    Last Post: 10-28-2019, 05:11 PM
  3. Need help with Looping
    By lccrews in forum Programming
    Replies: 5
    Last Post: 11-02-2018, 05:37 PM
  4. Looping
    By ddrew in forum Forms
    Replies: 8
    Last Post: 10-08-2012, 01:48 AM
  5. Looping through Records in SQL
    By make me rain in forum Queries
    Replies: 13
    Last Post: 07-17-2011, 08:58 AM

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