Results 1 to 10 of 10
  1. #1
    jo15765's Avatar
    jo15765 is offline Expert
    Windows 10 Access 2013 64bit
    Join Date
    Nov 2010
    Location
    6 Feet Under
    Posts
    672

    Unhide Fields On Sub Form


    I have a subform that is based off a query. What happens is you input a username in a textbox and push a button and a stored procedure is executed and a sub-form displays on screen with the results. This works, until someone hides a few of the columns in the sub-form! The only way I have found to "unhide them" is to highlight the entire sub-form, right click and say unhide.

    Is there a way I can use VBA to perform a check that no column is hidden before displaying the sub form to the user? (and of course if the column is hidden display it)

    I tried on the subform on load event to do this, but hidden columns remain hidden
    Code:
    Private Sub Form_Load()
    'Show any hidden field when the subform loads
    For Each ctrl In Me.[Form with space subform].Controls
       If ctrl.ControlType = acTextBox Then
          ctrl.ColumnHidden = False
       End If
    Next
    End Sub

  2. #2
    rpeare is offline VIP
    Windows XP Access 2003
    Join Date
    Jul 2011
    Posts
    5,442
    Have you got a sample database, I would rather not have to re-design something if you've got something handy.

    It may be as simple as cycling through controls on the subform and setting the hidden property to false

    Code:
    dim ctl as control
    
    for each ctl in me.controls
        if ctl.controltype = x then
            me.fieldname.columnhidden = -1 
            'or
            'me.fieldname.columnhidden = 0
        endif
    next ctl
    if you are calling it from within the subform

    list of control types here:
    https://msdn.microsoft.com/en-us/lib...ffice.11).aspx

  3. #3
    jo15765's Avatar
    jo15765 is offline Expert
    Windows 10 Access 2013 64bit
    Join Date
    Nov 2010
    Location
    6 Feet Under
    Posts
    672
    The line
    Code:
    Me.FieldName.
    throws an error of method or data member not found.

  4. #4
    rpeare is offline VIP
    Windows XP Access 2003
    Join Date
    Jul 2011
    Posts
    5,442
    try using the subform name then instead of me

    or forms("subformname").fieldname

    I don't use bound forms so someone may be able to help you better than I can with syntax.

    I would test it first just using

    debug.print ctl.name

    and see if it prints off a list of the controls properly. You really only want your data entry fields to show up when this debug.print goes off.

  5. #5
    jo15765's Avatar
    jo15765 is offline Expert
    Windows 10 Access 2013 64bit
    Join Date
    Nov 2010
    Location
    6 Feet Under
    Posts
    672
    Still no such luck. The only way I have seen to this point is to highlight and right click and say unhide.

  6. #6
    rpeare is offline VIP
    Windows XP Access 2003
    Join Date
    Jul 2011
    Posts
    5,442
    how about providing a sample of your database so I don't have to re-create something to do testing

  7. #7
    jo15765's Avatar
    jo15765 is offline Expert
    Windows 10 Access 2013 64bit
    Join Date
    Nov 2010
    Location
    6 Feet Under
    Posts
    672
    Database1.zip

    Look at form1 if you hide a field in the subform, how can VBA unhide the field?

  8. #8
    rpeare is offline VIP
    Windows XP Access 2003
    Join Date
    Jul 2011
    Posts
    5,442
    there's something wrong with your zip, I can't unzip it without getting a multi volume error.

  9. #9
    jo15765's Avatar
    jo15765 is offline Expert
    Windows 10 Access 2013 64bit
    Join Date
    Nov 2010
    Location
    6 Feet Under
    Posts
    672
    Try this version. I created the 1st one using 7zip - maybe that was the issue.
    Attached Files Attached Files

  10. #10
    rpeare is offline VIP
    Windows XP Access 2003
    Join Date
    Jul 2011
    Posts
    5,442
    I put a button on the main form with the following code

    Code:
    For Each ctl In Me.Controls("Data subform").Controls    If InStr(ctl.Tag, "DE") > 0 Then
            ctl.ColumnHidden = False
            ctl.ColumnWidth = -1
        End If
    Next ctl
    On the subform, set the TAG property of all the fields to DE (last property in the property window

    This worked fine for me

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

Similar Threads

  1. Replies: 1
    Last Post: 02-08-2016, 05:40 PM
  2. Replies: 2
    Last Post: 12-28-2012, 02:28 PM
  3. Replies: 1
    Last Post: 05-23-2011, 07:11 AM
  4. Replies: 1
    Last Post: 01-10-2011, 12:25 AM
  5. Hide or Unhide Fields in Query using VB
    By SCFM in forum Programming
    Replies: 4
    Last Post: 03-12-2010, 01:24 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