Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Hide all subform controls 1

Status
Not open for further replies.

Reggaefloww

Programmer
Apr 8, 2006
16
US
Hi guys,

I need help hiding all subform controls when a form opens
Thanks
 
In the form open event, add code like
YourControlName.Visible = False.

"Business conventions are important because they demonstrate how many people a company can operate without."
 
BTW if there are a lot of them, you can loop thru the controls collection with a For...Each loop.

"Business conventions are important because they demonstrate how many people a company can operate without."
 
In your specific case we hid the column of a datasheet not the control. These are different.
Code:
Private Sub Form_Open(Cancel As Integer)
  Dim myCntrl As Access.Control
  For Each myCntrl In Me.mySubform.Controls
    If myCntrl.ControlType = acTextBox Then
      myCntrl.ColumnHidden = False
    End If
  Next myCntrl
End Sub
 
How would it work for all controls regardless if they're textboxs or not?
 
Omit this line

If myCntrl.ControlType = acTextBox Then

and it corresponding End If.

The Missinglinq

Richmond, Virginia

There's ALWAYS more than one way to skin a cat!
 
Make sure you do not have any labels on your form if you get rid of the if. Labels do not have a columnhidden property and you will throw an error.

Also no other controls besides text box,list box,combo box, or check box.

 
I actually have the form working exactly the way I want it now, except for one problem. I have my code the exact opposite of how I want it. I want the user to choose the columns they want and show only those columns that have been selected. Right now I'm hiding the columns they selected, and showing all others lol.

Here's the code I'm currently using.
Dim strSql As String
Dim vItem As Variant
Dim NumFields As Integer
Dim intCounter As Integer
NumFields = 0
' loop through selected field names
For Each vItem In Me.lstFieldList.ItemsSelected
strSql = strSql & ",[" & Me.lstFieldList.ItemData(vItem) & "]"
NumFields = NumFields + 1
Next vItem

For intCounter = 0 To lstFieldList.ListCount - 1
For Each vItem In Me.lstFieldList.ItemsSelected
Me.subformCertData.Form.Controls(lstFieldList.ItemData(intCounter)).ColumnHidden = lstFieldList.Selected(intCounter)
Next vItem
Next intCounter
 
If an item is selected in a list box its "selected" property is true. If you want to hide a column of a datatsheet then the columnhidden property is true.

In you case you want to set the column hidden property to false if the selected property is true (show the column selected) so:

... .ColumnHidden = not(lstFieldList.Selected(intCounter))
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top