Results 1 to 14 of 14
  1. #1
    Access_Novice is offline Competent Performer
    Windows 7 64bit Access 2013
    Join Date
    Sep 2013
    Posts
    265

    Using the columnhidden property in on a List Box

    I have a list box with four columns: parentID, firstName, lastName and fullName. I am trying to hide the 2nd column (firstName). Right now, the List box is the only control on my form.




    I wasn't sure how to get this property to work just by returning to datasheet view, so for now, I put the code under the OnClick event:

    Private Sub listBoxParent_Click()
    Me.listBoxParent.[firstName].ColumnHidden = True
    End Sub


    The name of the list box is listBoxParent.

    1. Why isn't this working?
    2. Do I have to put this code under an event? Is there another way to automatically make the 2nd column hidden when I exit design view and enter datasheet view?

  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
    I'm not clear on the layout, but typically the columns in a listbox are controlled by its column widths property.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    Missinglinq's Avatar
    Missinglinq is offline VIP
    Windows 7 64bit Access 2007
    Join Date
    May 2012
    Location
    Richmond (Virginia, not North Yorkshire!)
    Posts
    3,018
    And that has to be set in Design View, if I remember correctly. Why would you want to hide a Column of a Listbox when clicking on the Listbox?
    The problem with making anything foolproof...is that fools are so darn ingenious!

    All posts/responses based on Access 2003/2007

  4. #4
    Access_Novice is offline Competent Performer
    Windows 7 64bit Access 2013
    Join Date
    Sep 2013
    Posts
    265
    Quote Originally Posted by Missinglinq View Post
    And that has to be set in Design View, if I remember correctly. Why would you want to hide a Column of a Listbox when clicking on the Listbox?
    The reason being that I may not want to display all of the fields that come over from the Row Source.

  5. #5
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    Typically you hide them in design view with the column widths property.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  6. #6
    Access_Novice is offline Competent Performer
    Windows 7 64bit Access 2013
    Join Date
    Sep 2013
    Posts
    265
    Quote Originally Posted by pbaldy View Post
    Typically you hide them in design view with the column widths property.
    Yes, I know how to do that. I was on the Microsoft website lookin a properties of the List Box and one was 'columnhidden' so I was just curious to see how that was used.

  7. #7
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,930
    One of the more confusing MS helps I've run into.

    ColumnHidden is also indicated as a textbox property. However, what really appears to be happening is a field/control is hidden when form is in Datasheet view, otherwise not relevant and code is ignored.

    http://office.microsoft.com/en-in/ac...080203741.aspx
    http://office.microsoft.com/en-in/ac...080203741.aspx
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  8. #8
    Access_Novice is offline Competent Performer
    Windows 7 64bit Access 2013
    Join Date
    Sep 2013
    Posts
    265
    Quote Originally Posted by June7 View Post
    One of the more confusing MS helps I've run into.

    ColumnHidden is also indicated as a textbox property. However, what really appears to be happening is a field/control is hidden when form is in Datasheet view, otherwise not relevant and code is ignored.

    http://office.microsoft.com/en-in/ac...080203741.aspx
    http://office.microsoft.com/en-in/ac...080203741.aspx
    I saw those sites. That is where I got the idea to try:

    Private Sub listBoxParent_Click()
    Me.listBoxParent.[firstName].ColumnHidden = True
    End Sub

    But I still can't get this to work. I am using 'Me' since I am in the form that contains the List Box, then I state the name of the list box. My attempt to specify which column I want to hide (firstName) is not working so I don't know what I am doing wrong.

    Any ideas?

  9. #9
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,930
    Read my previous post again. Note: "field/control is hidden when form is in Datasheet view"

    I just tested this and it does hide field/control. It does NOT hide a column of a combobox or listbox.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  10. #10
    Access_Novice is offline Competent Performer
    Windows 7 64bit Access 2013
    Join Date
    Sep 2013
    Posts
    265
    Quote Originally Posted by June7 View Post
    Read my previous post again. Note: "field/control is hidden when form is in Datasheet view"

    I just tested this and it does hide field/control. It does NOT hide a column of a combobox or listbox.
    I tried this again. I didn't see the field/control hidden when switched into Datasheet view so I don't know what I'm doing wrong. Also, I don't know why it would hide a field/control if the property name is columnHidden.

  11. #11
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,930
    I created a form called Airports and opened in Datasheet view. I ran this one line in the Immediate window:

    Forms!Airports!FAAID.ColumnHidden = True

    Zap! The column disappears from view.

    Forms!Airports!FAAID.ColumnHidden = False

    Zap! The column reappears.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  12. #12
    Access_Novice is offline Competent Performer
    Windows 7 64bit Access 2013
    Join Date
    Sep 2013
    Posts
    265
    Quote Originally Posted by June7 View Post
    I created a form called Airports and opened in Datasheet view. I ran this one line in the Immediate window:

    Forms!Airports!FAAID.ColumnHidden = True

    Zap! The column disappears from view.

    Forms!Airports!FAAID.ColumnHidden = False

    Zap! The column reappears.
    Ok. What is FAAID? Is it the name of the List Box, the column to be hidden, a text box?

  13. #13
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,930
    FAAID is name of field and also name of textbox/listbox/combobox (doesn't matter which control is used).

    If control has name different than the field, use name of control.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  14. #14
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows XP Access 2003
    Join Date
    Aug 2013
    Posts
    7,862
    Quote Originally Posted by Access_Novice View Post
    Ok. What is FAAID? Is it the name of the List Box, the column to be hidden, a text box?
    I don't see how the property "Column Hidden" is relevant to your List Box. As June7 pointed out, this property is for DS view of your form. As others have pointed out, your listbox has its own properties and if you want to hide a column within the listbox you will need to use the widths property of the list box control. The value of zero will hide that column within the listbox, respectively.

    Typicaly, this property is edited in design view. If you want it to be dynamicaly updated, you need to have a specific event fire some VBA code. I use code similar to the following to dynamicaly adjust the widths property for combos and list boxes.

    Code:
    Dim strQuote As String
    strQuote = """"
    Dim strWidths As String
    strWidths = "0" & strQuote & "; " & "0.6" & strQuote & "; " & "0.7" & strQuote & "; " & "0" & strQuote
    Me.cmbCont.ColumnWidths = strWidths
    This example hides the first column. Its value is zero. I do not want it displayed to the user because it contains a primary key value. It also hides the last column, the fourth column.

    .

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

Similar Threads

  1. Using VBA to set up all forms property
    By aspfun in forum Programming
    Replies: 1
    Last Post: 05-10-2013, 01:20 PM
  2. Property value is too large
    By Jean Kipling in forum Database Design
    Replies: 3
    Last Post: 01-30-2013, 05:04 PM
  3. Property value is too large.
    By foru in forum Access
    Replies: 9
    Last Post: 06-28-2011, 03:55 PM
  4. SQL vs. vba Row Source property
    By eww in forum Programming
    Replies: 7
    Last Post: 10-15-2010, 11:02 AM
  5. 'On Open' Property
    By emilylu3 in forum Forms
    Replies: 1
    Last Post: 12-08-2005, 02:28 PM

Tags for this Thread

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