Results 1 to 7 of 7
  1. #1
    banpreet is offline Competent Performer
    Windows 8 Access 2010 64bit
    Join Date
    Jul 2016
    Posts
    117

    Code to Lock or hide sections in form depending on value

    Hey guys,

    I have a form with 5 sections to be filled out. Section 1 is to be filled out by the customer but they won't know how to fill out section 3,4,5. Section 2 is to be filled out by a manager that will select a person that will help the customer to fill out the rest of the sections because they know what they are doing. This is a combo box and section 2 is a subform on the main form(don't know if it makes a difference). So when this combobox is not filled out, or doesn't have any value, I want section 3,4,5 to be invisible or locked. After only there is a value in section 2, then the sections will be visible or unlocked for the customer and the person helping them out to fill out the rest of the form. The combo box is named "cboAssignTestEngineer".



    Appreciate all the help!

  2. #2
    pbaldy's Avatar
    pbaldy is online now Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,518
    Generally:

    http://www.baldyweb.com/ConditionalVisibility.htm

    I might use a tab control and make tabs invisible.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    banpreet is offline Competent Performer
    Windows 8 Access 2010 64bit
    Join Date
    Jul 2016
    Posts
    117
    section 2 that needs to be filled out by a manager is on a subform, will this matter in locking the other subforms and other fields on the form?

    I have this code but doesn't seem to work.

    Private Sub Form_Current()

    If IsNull(Me.cboAssignTestEngineer) Then
    TR_Estimate_subform.Visible = False
    TR_Attachments.Visible = False
    TR_Parts.Visible = False
    End If


    Exit Sub

  4. #4
    pbaldy's Avatar
    pbaldy is online now Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,518
    What exactly does "doesn't seem to work" mean? I'd use the Else clause in my link.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  5. #5
    rpeare is offline VIP
    Windows XP Access 2003
    Join Date
    Jul 2011
    Posts
    5,442
    I'd tend to build a function like


    Code:
    Function Section1Toggle
    
    If IsNull(Me.cboAssignTestEngineer) Then
        TR_Estimate_subform.Visible = False
        TR_Attachments.Visible = False
        TR_Parts.Visible = False
    Else
        TR_Estimate_subform.Visible = True
        TR_Attachments.Visible = True
        TR_Parts.Visible = True
    End If


    then in the ON EXIT or ON CHANGE event of cboAssignTestEngineer you simply call the function

    If you do it this way you can activate/inactivate sections of your form without having to re-write your code

  6. #6
    pbaldy's Avatar
    pbaldy is online now Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,518
    I would also use a function, but I figured that was step 2 after getting the code to work.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  7. #7
    banpreet is offline Competent Performer
    Windows 8 Access 2010 64bit
    Join Date
    Jul 2016
    Posts
    117
    Ok I put it on_load event. When person first opens up the form, they can only see section 1 and 2. Before this form there are sections from another form that are carried on this form. Now when the manager goes into the form to select the person to help fill out the form with the customer, the fields values such as name and id that were carried on from the previos form are deleted as soon as the manager selects a person. Any clue why this happens?

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

Similar Threads

  1. Replies: 2
    Last Post: 09-11-2014, 11:37 PM
  2. Hide Sections of Access Ribbon
    By kazaccess in forum Programming
    Replies: 1
    Last Post: 08-19-2014, 10:09 PM
  3. Replies: 5
    Last Post: 03-15-2014, 05:27 PM
  4. Replies: 3
    Last Post: 01-08-2014, 06:37 PM
  5. Replies: 2
    Last Post: 06-06-2012, 10:53 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