Search code examples
ms-accesscomboboxvisible

Toggle visibility of other fields on form based upon combobox selection - MS Access


Question...

How can I toggle the visibility of several other fields (checkboxes/textboxes) on form based upon the selection of a combobox item. The image below shows a listbox but either way, how do use vba code to turn on or off visibility of all the fields in the grey box. Basically, if the combobox selection is scheduled then visible=true. Else visible=false How can I code this???

example


Solution

  • Use combobox AfterUpdate event and probably form Current event as well. So build a procedure that can be called from both events, something like:

    Sub Form_Current()
    SetVisible
    End Sub
    
    Sub cbo1_AfterUpdate()
    SetVisible
    End Sub
    
    Sub SetVisible()
    Me.tbx1.Visible = Me.cbo1 = "scheduled"
    Me.cbx1.Visible = Me.cbo1 = "scheduled"
    End Sub
    

    Alternative is to use Conditional Formatting for textboxes and comboboxes (sorry, not applicable to other controls) to Enable/Disable as well as set colors so appear not visible.