Page 1 of 3 123 LastLast
Results 1 to 15 of 42
  1. #1
    5 Star Lounger
    Join Date
    May 2003
    Location
    Sheffield, Yorkshire
    Posts
    951
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Hide control (2003)

    I have a subform on a form, and based on an option button on the main form, want to hide a control on the subform. Is this possible?

  2. #2
    Gold Lounger
    Join Date
    Jun 2001
    Location
    Crystal Beach, FL, Florida, USA
    Posts
    3,436
    Thanks
    1
    Thanked 34 Times in 34 Posts

    Re: Hide control (2003)

    Yes, it is very easy. Put this code in your mainform's Current event and the AfterUpdate event of that option button:

    subformcontrolname.form.controlname.visible = optButton (or: Not optButton)

    Make sure you use the subform's controlname (which may not be the same as the subform name itself).
    Mark Liquorman
    See my website for Tips & Downloads and for my Liquorman Utilities.

  3. #3
    5 Star Lounger
    Join Date
    May 2003
    Location
    Sheffield, Yorkshire
    Posts
    951
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Re: Hide control (2003)

    So the subforms control name comes before the main form? And what's the other control name before.visible? I'm getting 'object required'

  4. #4
    Gold Lounger
    Join Date
    Jun 2001
    Location
    Crystal Beach, FL, Florida, USA
    Posts
    3,436
    Thanks
    1
    Thanked 34 Times in 34 Posts

    Re: Hide control (2003)

    Let's assume your subform controlname is "subDetail", the control on subform you want to make visible/invisible is "txtWhatever", and checkbox on mainform is named "chkWhatever". The code would be:

    subDetail.form!txtWhatever.Visible = chkWhatever

    This will make txtWhatever visible when chkWhatever is checked. If you want it visible when chkWhatever is not checked, then use: = NOT chkWhatever
    Mark Liquorman
    See my website for Tips & Downloads and for my Liquorman Utilities.

  5. #5
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Hide control (2003)

    In Mark's expression

    subformcontrolname.form.controlname.visible = optButton

    subformcontrolname must be replaced with the name of the subform as a control on the main form, and controlname must be replaced with the name of the control on the subform that you want to hide. Finally, optButton must be replaced with the name of the option button.

  6. #6
    4 Star Lounger
    Join Date
    Jan 2002
    Location
    Brookings, South Dakota, USA
    Posts
    449
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Hide control (2003)

    Hi Rob,
    See if this helps you decipher referencing the controls and properties.
    I keep a copy of this posted on the bulletin board by my desk because I can never seem to remember all the little nuances.

    The Access Web
    <IMG SRC=http://www.wopr.com/w3tuserpics/gdrezek_sig.jpg>
    "Those who dance are considered insane by those who can't hear the music" - George Carlin

  7. #7
    5 Star Lounger
    Join Date
    May 2003
    Location
    Sheffield, Yorkshire
    Posts
    951
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Re: Hide control (2003)

    I've got
    tblRobot_subform.Form!TIME_ON.Visible = Not Option443 in OnCurrent and AfterUpdate of the Option443

    and the code opens up with the code highlighted yellow. Clearly not working.
    It's on the form I sent Hans <post#=589,954>post 589,954</post#>. When I click a check box, I want TIME_ON on the tblRobot subform to be hidden. I've typed it as you explained, but I think there may be something wrong elsewhere.

  8. #8
    Gold Lounger
    Join Date
    Jun 2001
    Location
    Crystal Beach, FL, Florida, USA
    Posts
    3,436
    Thanks
    1
    Thanked 34 Times in 34 Posts

    Re: Hide control (2003)

    Is tblRoot_subform the name of the subform control that sits on the mainform? It doesn't matter what the actual name of the form contained by the subform control. And is TIME_ON the name of a control?
    Mark Liquorman
    See my website for Tips & Downloads and for my Liquorman Utilities.

  9. #9
    5 Star Lounger
    Join Date
    May 2003
    Location
    Sheffield, Yorkshire
    Posts
    951
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Re: Hide control (2003)

    Yes, tblRobot_subform is the name of the subform control, and TIME_ON is the name of a control on the subform that I want to hide.

  10. #10
    Gold Lounger
    Join Date
    Jun 2001
    Location
    Crystal Beach, FL, Florida, USA
    Posts
    3,436
    Thanks
    1
    Thanked 34 Times in 34 Posts

    Re: Hide control (2003)

    TIME_ON is also the name of a field. Try changing the name of the control to txtTIME_ON, and change your code to reflect this. As a rule of thumb, you should always change your control names so they don't match the controlsource. Unfortunately, this is what Access uses when it creates the control names.
    Mark Liquorman
    See my website for Tips & Downloads and for my Liquorman Utilities.

  11. #11
    5 Star Lounger
    Join Date
    May 2003
    Location
    Sheffield, Yorkshire
    Posts
    951
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Re: Hide control (2003)

    Still highlighted as an error on the After Update code

  12. #12
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Hide control (2003)

    There is no Option443 on the form from that post.
    It's rather confusing to mention an option button when you mean a check box.
    Setting Visible to False will not work since your subform is in datasheet view. You must set the ColumnHidden property instead.
    See attached version (I added a check box perversely named Option443)

  13. #13
    5 Star Lounger
    Join Date
    May 2003
    Location
    Sheffield, Yorkshire
    Posts
    951
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Re: Hide control (2003)

    Hiding this control was only decided upon after I had posted you a copy of the database, that's why there is no checkbox. The original idea was to hide the whole form, which I had done. I mistakenly thought that a checkbox and option button could be used for the same thing. I have learnt another valuble lesson. Thanks Hans, and to all of you, for your assistance. Even our IT bod was baffled.

  14. #14
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Hide control (2003)

    You *can* use a check box and an option button almost interchangeably, but in general, option buttons are used in groups to let the user select one of several options, while a check box is used to turn a single option on or off. Windows users are accustomed to this, so if you deviate from it, it can be confusing.

  15. #15
    Gold Lounger
    Join Date
    Jun 2001
    Location
    Crystal Beach, FL, Florida, USA
    Posts
    3,436
    Thanks
    1
    Thanked 34 Times in 34 Posts

    Re: Hide control (2003)

    I don't know why you are getting an error. There is one change you need to make, however. Because you subform contains a datasheet, you must set the .columnhidden property rather than use the .visible property. Like this:

    tblRobot_subform.Form!TIME_ON.columnHidden = Option443

    I tried this on your form from the download, and it works perfectly, although I used a checkbox that I added since OPtion443 wasn't there.
    Mark Liquorman
    See my website for Tips & Downloads and for my Liquorman Utilities.

Page 1 of 3 123 LastLast

Posting Permissions

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