how can I add or remove fields

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Busbait
    New Member
    • Sep 2007
    • 18

    how can I add or remove fields

    Hi,

    I have a Form and SubFrom in MS Access 2007 , the SubForm default view is “Datasheet”

    Now, after I run the main Form with the imbedded SubForm , how can I add or remove fields form the SubFrom using VB ( adding and removing fields will be controlled from the main Form)

    Your help is highly appreciated.
  • hjozinovic
    New Member
    • Oct 2007
    • 167

    #2
    hi Busbait,

    You probably want to be able to show/hide columns on your subform.
    To do this you could use a code like this:
    Code:
    Dim ctl As Control
    Dim ctlName As String
    Private Sub Combo5_Enter()
    Me!Combo5.RowSource = ""
    For Each ctl In Me!sfTable1.Form.Controls
    If ctl.ControlType = acTextBox Then
    Me!Combo5.AddItem ctl.Name
    End If
    Next ctl
    End Sub
    
    Private Sub btnHide_Click()
    ctlName = Me!Combo5
    Set ctl = Me!sfTable1.Form.Controls(ctlName)
    ctl.ColumnHidden = True
    End Sub
    This is something I just tested and it works great.
    I have a comboBox on the main form.
    It lists all the columns from your subform.
    After you select one from the list, you would click on btnHide to hide the column.
    This should get you on th right track.
    regards, h.

    Comment

    • Busbait
      New Member
      • Sep 2007
      • 18

      #3
      Thanks ....... hjozinovic

      It works fine

      Comment

      Working...