Results 1 to 9 of 9
  1. #1
    Join Date
    Nov 2003
    Location
    Europe
    Posts
    369

    Unanswered: hide controls on a subform based on optGroup in the main form?

    I have a subform with 3 date fields. Depending on which option is chosen in the main form, I want only the related field/control/column (datasheet view in the subform) to show, the others should be set to hidden or visible=no. How do I do that in VBA?

  2. #2
    Join Date
    Sep 2003
    Location
    MI
    Posts
    3,713
    try:

    Me![SubformControlNameHere].Form.ControlNameHere.Visible=False

  3. #3
    Join Date
    Oct 2003
    Location
    Roanoke, Va
    Posts
    445

    Re: hide controls on a subform based on optGroup in the main form?

    Originally posted by kedaniel
    I have a subform with 3 date fields. Depending on which option is chosen in the main form, I want only the related field/control/column (datasheet view in the subform) to show, the others should be set to hidden or visible=no. How do I do that in VBA?
    You can also check out the ColumnHidden property in the help files to hide and show datasheet columns.

    A brief exerpt:

    ColumnHidden Property

    You can use the ColumnHidden property to show or hide a specified column in Datasheet view. Read/write Boolean.

    expression.ColumnHidden

    expression Required. An expression that returns one of the objects in the Applies To list.

    Setting
    You can set the ColumnHidden property by clicking Hide Columns or Unhide Columns on the Format menu in Datasheet view.

    You can also set this property in a Microsoft Access database (.mdb) by using a Long Integer value in Visual Basic to specify the following settings.

    Setting Description
    True The column is hidden.
    False (Default) The column is visible.

    Gregg

  4. #4
    Join Date
    Nov 2003
    Location
    Europe
    Posts
    369
    Originally posted by M Owen
    try:

    Me![SubformControlNameHere].Form.ControlNameHere.Visible=False
    None of these works:
    Me![subfrmContractStatus].Form.dep_paid.Visible = False
    Me.subfrmContractStatus.Form.dep_paid.Visible = False

    When I use the ! after Me, nothing is suggested, when using the . (dot), Access suggests the subform among other items, but when I come to Form. - the dep_paid field is not suggested. I am not certain about the difference of using ! and . ...

  5. #5
    Join Date
    Nov 2003
    Location
    Europe
    Posts
    369

    Re: hide controls on a subform based on optGroup in the main form?

    Originally posted by basicmek
    You can also check out the ColumnHidden property in the help files to hide and show datasheet columns.

    expression.ColumnHidden

    expression Required. An expression that returns one of the objects in the Applies To list.

    You can also set this property in a Microsoft Access database (.mdb) by using a Long Integer value in Visual Basic to specify the following settings.

    Setting Description
    True The column is hidden.
    False (Default) The column is visible.

    Gregg
    OK, I am afraid I am not enough of a programmer to make sense of that. Could you provide an example expression/usage for referring to a control on a subform?
    I always need to look at existing code to manage to write new in the proper way.

  6. #6
    Join Date
    Sep 2003
    Location
    MI
    Posts
    3,713
    Ok. Couple things to verify: (since that is the code I USE with the subform in my form ...)

    What is the name of the subform control on your main form (NOT the name of the subform itself)? Is it "subfrmContractStatus"? If not then you need to put THAT name between the []'s ...

  7. #7
    Join Date
    Nov 2003
    Location
    Europe
    Posts
    369
    Originally posted by M Owen
    What is the name of the subform control on your main form (NOT the name of the subform itself)? Is it "subfrmContractStatus"? If not then you need to put THAT name between the []'s ...
    subfrmContractStatus is the name of the control, and subfrm_cc_ctrStatus_sent is the name of the (sub)form itself

  8. #8
    Join Date
    Dec 2002
    Location
    Préverenges, Switzerland
    Posts
    3,740
    if i remember correctly you should drop the !Form if you are trying to address a control on the form (as opposed to addressing e.g. the .Detail section of the form as a whole).

    so, try:
    Me![subfrmContractStatus].dep_paid.Visible = False

    (and i guess that:
    Me![subfrmContractStatus]!dep_paid.Visible = False
    also works but i forget which of the two is the official syntax)

    but
    Me![subform]!Form.Detail.visible =

    izy
    currently using SS 2008R2

  9. #9
    Join Date
    Nov 2003
    Location
    Europe
    Posts
    369
    Originally posted by izyrider
    so, try:
    Me![subfrmContractStatus].dep_paid.Visible = False
    (and i guess that:
    Me![subfrmContractStatus]!dep_paid.Visible = False
    also works but i forget which of the two is the official syntax)
    izy
    None of the above works, when I try to enter ]!form.dep_paid instead of ]!dep_paid , at least I get a specific error; "cant find the field "Form" ..." , which I do not get when I omit it, which should prove that dep_paid is recognised, even if when I type the ! - before - or when I type the . after dep_paid, nothing is suggested, so I do not know if Visible is the correct word. Although when I leave the line, the v in visible is automatically made Capital letter. Should that indicate that it is a valid "term"?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •