Hiding controls in Access

philippe58 -  
incaout Posted messages 347 Registration date   Status Member Last intervention   -
Hello,
I am stuck on a piece of VBA code that would make certain controls invisible based on a determined value in a choice list. Indeed, this choice list has 2 options, and depending on one or the other, I need to make certain controls visible and hide others.
Thank you in advance
Configuration: Windows XP Internet Explorer 7.0

3 answers

  1. incaout Posted messages 347 Registration date   Status Member Last intervention   74
     
    Hi.

    Use the "visible" property of the control you want to hide or show:

    control.visible = true: shows
    control.visible = false: hides.

    Regards

    IC
    0
  2. philippe58
     
    Good evening and thank you for the info, but I don't know vb at all and I'm wondering how I should start this code and how I should call my different controls.
    Thank you.
    0
  3. incaout Posted messages 347 Registration date   Status Member Last intervention   74
     
    Hello,

    You need to associate the code with an event for your choice list. You can do this in the properties window of your choice list in the "Event" tab. There you'll find a list of all possible events for your control. For example, on the "onclick" event, if you click the button at the end of the line "...", you have a window where you choose "code generator". You will then arrive at a VBA page.

    Assuming your list is named "maliste", you will have this:

    sub maliste_onclick()

    end sub

    This corresponds to the program that will be executed every time you click on your list.

    So you just need to add the code to hide the controls.

    sub maliste_onclick()

    'Re-display all controls. I'm assuming that each line hides one or more controls,
    'but that they do not accumulate

    for each ctl in Controls
    ctl.visible = true
    next ctl

    'Retrieve the selected line
    choix = maliste.value

    'Test the value of the choice and hide the corresponding controls

    select case choix

    case "cas1" :
    me.NomduControle1.visible = false
    me.NomduControle3.visible = false

    case "cas2" :
    me.NomDuControle2.visible = false

    end select

    end sub

    You need to replace "cas1" and "cas2" with the values found in the list box that trigger the hiding of controls. You also need to replace "NomDuControle" with the actual names of the relevant controls.

    You can also choose "onchange" or "afterupdate" as the triggering event

    Good luck

    IC

    PS: I hope I didn't make any syntax errors.
    0