Results 1 to 5 of 5
  1. #1
    Annnnn is offline Novice
    Windows 10 Access 2007
    Join Date
    Feb 2018
    Posts
    17

    Hidding columns in a subform

    Hi!



    I am trying to hide certain columns in a subform but somehow it doesn't work

    My subform shows more columns than I need for one application,
    so upon a button click I run a certain SQL code (via VBA) and with the same click I would like to hide the abundant columns.

    Code:
    Private Sub btCompose_Click()
    
    
    'shows the new samples that have to be in an experiment
    
    
    Dim db As DAO.Database
    Dim qdf As DAO.QueryDef
    Dim VarItm As Variant
    Dim strCriteria As String
    Dim strSQL As String
    
    
    
    
    Set db = CurrentDb()
    Set qdf = db.QueryDefs("qrBiopt_iso")
    
    
    
    
    strSQL = "SELECT tblSamples.Sample_name, tblSamples.Primary_tumor_type, tblSamples.Biopsy_material, tblSamples.Sample_barcode AS [Biopsy barc 1], " & _
            "tblSamples.Biopsy_barc_2, tblSamples.Biopsy_barc_3, tblSamples.Biopsy_barc_4, tblSamples.Coupes_barcode, tblSamples.Pathologie_exp , tblSamples.Tumor_ " & _
            "FROM tblSamples " & _
            "WHERE tblSamples.Pathologie = 'Finished';"
            
    qdf.sql = strSQL
    
    
    Set db = Nothing
    Set qdf = Nothing
    
    
    'change record sourse for the subform to match strSQL, and update the subform
    Forms!Biopsy_iso!Sub_iso_biopsy.Form.RecordSource = strSQL
    
    'suppose to hide patient name collumn but doesnt work
    Forms![Biopsy_iso]![Sub_iso_biopsy].Form![Patient_name].ColumnHidden = False
    
    
    
    
    End Sub
    I thought it wouldn't be this complicated but somehow I do something wrong...

  2. #2
    isladogs's Avatar
    isladogs is offline MVP / VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    5,977
    Why use code if you don't want to ever see the columns
    For a datasheet, right click the column(s) and select Hide Columns
    For Single or Continuous forms, remove the controls or set as visible=false
    Colin, Access MVP, Website, email
    The more I learn, the more I know I don't know. When I don't know, I keep quiet!
    If I don't know that I don't know, I don't know whether to answer

  3. #3
    Gicu's Avatar
    Gicu is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jul 2015
    Location
    Kelowna, BC, Canada
    Posts
    4,115
    To hide the column you set the ColumnHidden to True:
    Code:
    Forms![Biopsy_iso]![Sub_iso_biopsy].Form![Patient_name].ColumnHidden = True

  4. #4
    Annnnn is offline Novice
    Windows 10 Access 2007
    Join Date
    Feb 2018
    Posts
    17
    Quote Originally Posted by Gicu View Post
    To hide the column you set the ColumnHidden to True:
    Code:
    Forms![Biopsy_iso]![Sub_iso_biopsy].Form![Patient_name].ColumnHidden = True
    haha so close yet so far! Tnx

    @ridders52 I'm using the same subform for multiple applications, some need extra columns then others. To avoid abundant columns i would like to hide some depending on the code that is running

  5. #5
    isladogs's Avatar
    isladogs is offline MVP / VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    5,977
    Fair enough.
    I have to admit I didn't notice the true/false error myself either
    Colin, Access MVP, Website, email
    The more I learn, the more I know I don't know. When I don't know, I keep quiet!
    If I don't know that I don't know, I don't know whether to answer

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

Similar Threads

  1. Hide / View columns in Subform
    By Alex Motilal in forum Forms
    Replies: 4
    Last Post: 06-24-2018, 09:45 PM
  2. Getting a Subtotal from columns in a Subform
    By dweekley in forum Access
    Replies: 3
    Last Post: 05-01-2017, 12:29 PM
  3. Autowidth for columns in subForm
    By rockstar283 in forum Access
    Replies: 13
    Last Post: 07-10-2014, 09:26 PM
  4. Subform with dynamic number of columns
    By modbass in forum Programming
    Replies: 1
    Last Post: 12-15-2011, 03:39 AM
  5. Visible property in subform columns
    By MDB in forum Forms
    Replies: 3
    Last Post: 09-03-2011, 06:46 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