Results 1 to 5 of 5
  1. #1
    Alex Motilal is offline Competent Performer
    Windows XP Access 2007
    Join Date
    Nov 2008
    Location
    Coimbatore, India
    Posts
    192

    Hide / View columns in Subform

    I am using the following code (got from Access Template) in a Command Button to view / hide columns in a Form:



    Private Sub cmdShowHideColumns_Click()
    On Error GoTo cmdShowHideColumns_Click_Err

    DoCmd.RunCommand acCmdUnhideColumns

    cmdShowHideColumns_Click_Exit:
    Exit Sub

    cmdShowHideColumns_Click_Err:
    MsgBox Error$
    Resume cmdShowHideColumns_Click_Exit

    End Sub

    I want to place the Command Button on the Main Form & View or Hide columns in the Subform. Is it possible? And if so how I should modify the code.

    Regards,
    Alex
    ?

  2. #2
    Bob Fitz's Avatar
    Bob Fitz is offline Access Developer
    Windows 7 32bit Access 2013
    Join Date
    May 2011
    Location
    Essex UK
    Posts
    3,544
    A couple of questions
    Is your sub form in datasheet view?
    Which columns are to be shown/hidden with this one button?
    If this helped, please click the star at the bottom left of this posting and add to my reputation . Many thanks.
    Bob Fitzpatrick

  3. #3
    Alex Motilal is offline Competent Performer
    Windows XP Access 2007
    Join Date
    Nov 2008
    Location
    Coimbatore, India
    Posts
    192
    Thanks Bob. The Subform is a Datasheet.
    If it is a Datasheet in the Main Form, clicking the button will generate a Popup Form showing all the columns. We can check whatever column we need to hide or view. I just want like that. I got the code from the Students Template in Access 2016.
    Regards
    Alex

  4. #4
    Bob Fitz's Avatar
    Bob Fitz is offline Access Developer
    Windows 7 32bit Access 2013
    Join Date
    May 2011
    Location
    Essex UK
    Posts
    3,544
    When I did this in an application that I developed I changed the ColumnWidth property with vba.
    Something like:
    Form.ControlName.ColumnWidth=0 (hides column)
    Form.ControlName.ColumnWidth=-2 (shows column)
    If this helped, please click the star at the bottom left of this posting and add to my reputation . Many thanks.
    Bob Fitzpatrick

  5. #5
    Alex Motilal is offline Competent Performer
    Windows XP Access 2007
    Join Date
    Nov 2008
    Location
    Coimbatore, India
    Posts
    192
    I used this code on the click event of the Command Button on the Main Form & succeeded.

    Private Sub CommandHideView_Click()
    Me.NameOfSubform.SetFocus
    DoCmd.RunCommand acCmdUnhideColumns
    End Sub

    Alex

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

Similar Threads

  1. Hide Button in sub form view
    By Derrick T. Davidson in forum Programming
    Replies: 5
    Last Post: 01-27-2016, 07:13 AM
  2. Replies: 1
    Last Post: 07-16-2015, 11:55 PM
  3. show / hide columns based on criteria?
    By stevepcne in forum Access
    Replies: 1
    Last Post: 11-18-2011, 02:49 PM
  4. Hide records from Form View
    By Douglasrac in forum Forms
    Replies: 9
    Last Post: 05-13-2011, 11:55 AM
  5. Show/Hide Columns in a Query
    By SCFM in forum Access
    Replies: 1
    Last Post: 02-23-2010, 08:04 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