Results 1 to 10 of 10
  1. #1
    Ian120 is offline Novice
    Windows 8 Access 2016
    Join Date
    Jan 2023
    Posts
    23

    How to hide data boxes with Yes/No check boxes?


    Hi all, I am making a form to fill in what customers ask for, and the data will go to the tables.

    There are a few types of products the customers can ask for, for instances the STC18 and STC24. What I would like to do is to allow the fill-in of the Height and Width of STC 18/24 only when the corresponding check boxes (Need STC18 & Need STC24) are/is checked. Like when the customer does not need STC24, I don't want the form to let users fill in the Height and Width of STC24. So, I am looking for a way to unhide/enable the labels and boxes after checking the check boxes. I think it would require after-update-event and most likely VBA codes which I barely have knowledge on them both.

    On the right of the picture is the query I used to merge the two tables and source this form from. I tried typing 'Need18=Yes' under "Criteria" of "STC18_H" and "STC18_W", but it didnt work as intended. Instead, it gives me an error in the form design page.

    Any idea is really appreciated and welcome! Thanks for the help!
    Attached Thumbnails Attached Thumbnails access_7.jpg  

  2. #2
    Gicu's Avatar
    Gicu is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jul 2015
    Location
    Kelowna, BC, Canada
    Posts
    4,085
    Ian, I suggest you start learning some VBA if you want to customize your app beyond basic functionality.

    Yes, the AfterUpdate event of the check box(es) would be a good place to either hide\make visible (.Visible=False\True) or disable\enable(.Enabled=False\True) the associated controls.

    Give it a try and post back if you get stuck !

    Cheers,
    Vlad Cucinschi
    MS Access Developer
    http://forestbyte.com/

  3. #3
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,738
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  4. #4
    June7's Avatar
    June7 is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,735
    Can use Conditional Formatting to enable/disable textboxes and comboboxes.
    No VBA needed.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  5. #5
    Ian120 is offline Novice
    Windows 8 Access 2016
    Join Date
    Jan 2023
    Posts
    23
    Hi guys, I think I am getting somewhere with After-Update event codes, though I am not sure how to do it with Conditional Formatting. I am using the following codes:

    Private Sub Need18_AfterUpdate()

    If Need18 Then
    STC18_H.Enabled = True
    STC18_W.Enabled = True
    Else
    STC18_H.Enabled = False
    STC18_H.Value = 0
    STC18_W.Enabled = False
    STC18_W.Value = 0
    End If

    End Sub

    However, I found some bugs, or something not intended anyway while I am scrolling between existing pages of the form. For example, page 1 and 2 are existing pages, data I am modifying instead of adding anew. The text boxes are default disabled. On page 1, I checked Need18, then the boxes for Height and Width are enabled and so I can fill in data. But when I turn to page 2, the corresponding customer doesn't need the product, so Need18 was not checked (before I made any changes). But the text boxes are enabled already anyway. I assume it is because the boxes are enable from the "checked" status from my last modifications on the previous page. If I uncheck the Need18 on page 2, the text boxes will grey out on page 2. But when I turn to page 1, those boxes are greyed out as well even though Need18 on page 1 is checked and those text boxes contains data previously entered.

    I would like the text boxes to be enabled WHENEVER the Need18 is checked. So, probably something that checks the value at all time, not after update. Is there something like that in Access?

  6. #6
    June7's Avatar
    June7 is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,735
    It's not a bug. If you set property with VBA it will apply to all instances of control, every record will have the same setting. So also need code in form Current event.

    Use Conditional Formatting and property will be set appropriately for every record at same time. Although, might see slower performance in form behavior.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  7. #7
    Ian120 is offline Novice
    Windows 8 Access 2016
    Join Date
    Jan 2023
    Posts
    23
    Thanks. I used OnCUrrent instead, it worked!

  8. #8
    June7's Avatar
    June7 is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,735
    Probably should have code in 3 events. Each checkbox AfterUpdate and form Current. Or, again, use Conditional Formatting and no VBA.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  9. #9
    Ian120 is offline Novice
    Windows 8 Access 2016
    Join Date
    Jan 2023
    Posts
    23
    Hi, June. Would you mind showing me briefly how to do it with Conditional Formatting? I googled about it but didn't understand how to do it without VBA. Thanks.

  10. #10
    June7's Avatar
    June7 is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,735
    CF rule references checkbox control which should return either True or False:

    Expression Is: Not [Need18]

    Then click the Enable icon in the rule. If Need18 is true the control will be enabled.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

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

Similar Threads

  1. Replies: 2
    Last Post: 10-07-2020, 10:30 AM
  2. Filtering form data with check boxes
    By Bkper087 in forum Access
    Replies: 1
    Last Post: 07-15-2019, 11:33 PM
  3. Replies: 5
    Last Post: 10-09-2017, 07:19 AM
  4. Check boxes to add data?
    By PaintTheMoonRed in forum Access
    Replies: 1
    Last Post: 04-18-2014, 09:14 AM
  5. Check Boxes saving log in data?
    By Z1nkstar in forum Access
    Replies: 1
    Last Post: 03-20-2014, 01:29 PM

Tags for this Thread

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