Results 1 to 8 of 8
  1. #1
    degras is offline Advanced Beginner
    Windows 7 Access 2007
    Join Date
    Nov 2010
    Posts
    72

    Hiding fields in a subform


    Hi,
    I have a form with a category field on it. The value for the category is selected from a list. Depending upon which value is selected for the category I want to hide or make visible various fields on a subform. So for example: only if the category is "Service" do I want the "Qty" field to be visible on the subform. How is this possible?
    Thanks

  2. #2
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    degras is offline Advanced Beginner
    Windows 7 Access 2007
    Join Date
    Nov 2010
    Posts
    72

    Hide fields not working

    Hi, thanks for the links. I wrote some VBA code but it is not working. I put the following code in the "On Change" event:

    Private Sub Category_Change()
    Me!ItemsSubform.Form!Totals.SetFocus
    Me!ItemsSubform.Form!ItemDate.Visible = False

    If Me.Category = "Service" Then
    Me!ItemsSubform.Form!ItemDate.Visible = True
    End If
    End Sub

    The problem is, when I change the category on the main form to something other than "Service", the ItemDate on the subform still remains visible.

  4. #4
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    Not sure, as I just tested and this worked as expected:

    Code:
    Private Sub Combo30_AfterUpdate()
      If Me.Combo30 = "Paul" Then
        Me.SubformControlName.Form.TextboxName.Visible = False
      Else
        Me.SubformControlName.Form.TextboxName.Visible = True
      End If
    End Sub
    You generally have to set focus first to the subform itself before setting focus to a control on the subform. I'd also use the after update event rather than the change event. The change event fires with each keystroke; the after update won't fire until the user is done.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  5. #5
    degras is offline Advanced Beginner
    Windows 7 Access 2007
    Join Date
    Nov 2010
    Posts
    72
    I added the location of my database as a trusted location and put the code in the AfterUpdate event, but the code still gets ignored. All the controls remain visible, despite setting their visible property to false. I don't get any error message. Is there any other reason why the code is not executing? Do I need to refresh the subform or something like that? I know the code is being read by VBA because if I try to mispell one of the control names I get an error message when the code runs.
    Last edited by degras; 01-13-2011 at 06:42 AM.

  6. #6
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    Can you post the db, or a representative sample?
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  7. #7
    degras is offline Advanced Beginner
    Windows 7 Access 2007
    Join Date
    Nov 2010
    Posts
    72
    Apparently the Visible property has no effect on controls on a datasheet, so I used the ColumnHidden property instead.
    Last edited by degras; 01-18-2011 at 09:42 AM.

  8. #8
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    Glad you sorted it out.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

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

Similar Threads

  1. How to link subform using two fields
    By rohnds in forum Forms
    Replies: 1
    Last Post: 08-04-2010, 04:44 AM
  2. Hiding fields that contains empty records
    By sakthivels in forum Reports
    Replies: 4
    Last Post: 05-27-2009, 07:06 AM
  3. how to hide the fields in subform
    By tinytree in forum Forms
    Replies: 3
    Last Post: 05-01-2009, 07:56 AM
  4. Accessing subform fields
    By nkenney in forum Forms
    Replies: 1
    Last Post: 04-21-2009, 10:10 PM
  5. Replies: 1
    Last Post: 10-26-2007, 07:29 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