Results 1 to 6 of 6
  1. #1
    rand605 is offline Novice
    Windows 7 Access 2007
    Join Date
    Dec 2009
    Posts
    4

    Smile Better way to turn visible properties on and off

    I have a form with a number of controls on it. Based what the user select from the first dropdown list, controls will become visible. This is the code that does this:

    Select Case WasteWaterDisposalTypeID
    Case 1
    Me.Disposal_Tank_Type_Label.Visible = True
    Me.TankTypeID.Visible = True
    Me.Disposal_Tank_Size__gallons__Label.Visible = True
    Me.TankSizeID.Visible = True
    Me.Type_of_Pipe_Label.Visible = True
    Me.PipeTypeID.Visible = True
    Me.LengthPipe_Label.Visible = True
    Me.LengthPipeLabel.Visible = True
    Me.FieldLength_Label.Visible = True
    Me.PipeFieldLength.Visible = True
    Me.FieldLengthIn_label.Visible = True
    Me.PipeFieldLengthIn.Visible = True
    Me.FieldLengthFtIn_label.Visible = True
    Me.PipeFieldLengthFt.Visible = True
    Me.HouseToTankLength_Label.Visible = True
    Me.HouseToTankLength.Visible = True
    Me.HouseToTankLengthIn_Label.Visible = True
    Me.HouseToTankLengthIn.Visible = True
    Me.HouseToTankLengthFt_Label.Visible = True
    Me.HouseToTankLengthFt.Visible = True
    Me.TankToDaylight_Label.Visible = True
    Me.TankToDayLightLength.Visible = True
    Me.TankToDayLightLengthIn_Label.Visible = True
    Me.TankToDayLightLengthIn.Visible = True
    Me.TankToDayLightLengthFt_Label.Visible = True
    Me.TankToDayLightLengthFt.Visible = True
    Me.NumberOfCleanOuts_Label.Visible = True
    Me.NumberOfCleanOuts.Visible = True



    End Select



    My question is there a better way to do this instead of having to to each control seperately?

  2. #2
    llkhoutx is offline Competent Performer
    Windows Vista Access 2007
    Join Date
    Jan 2010
    Location
    Houston, Texas USA
    Posts
    373
    There's nothing wrong with the way you are doing it.

    You could store a flag, i.e. 1, in the tag property of each of those controls, then on the Select Case event cycle through all form controls, testing their flag property and hide/display them as appropriate. The advantage of this is that you can add control and set their tag property appropriately and no code needs to be changed.

  3. #3
    dcrake's Avatar
    dcrake is offline Competent Performer
    Windows XP Access 2003
    Join Date
    Aug 2009
    Posts
    435
    Also if the label is associated to the control then you do not need to make the lable visible/invisible. That will reduce it by 50%

    David

  4. #4
    rand605 is offline Novice
    Windows 7 Access 2007
    Join Date
    Dec 2009
    Posts
    4
    Could you send me a example of using the case statement using the tag statement.

  5. #5
    sesproul is offline Advanced Beginner
    Windows Vista Access 2007
    Join Date
    Jan 2010
    Posts
    50
    Code:
    Public Function SwitchVisibleByTag (Byval v_bVisible as boolean, ByVal v_sTag as string)
    '---Pass in on or off for visible through the v_bVisible parameter
    '---Also pass in the TAG identifier to search for (This is a generic function)
    
    
    Dim ocontrol As Control
    
    
    Select Case WasteWaterDisposalTypeID
    Case 1
    
         'check every control for the tag and then appropriately set visibility
         For Each ocontrol In Me.Controls '---replace Me. with a specific form, or pass in the form parameter if function lives outside the form module.
             If ocontrol.Tag = v_sTag Then ocontrol.Visible = v_bVisible
         Next
    
    end Select
    
    
    end Function

  6. #6
    llkhoutx is offline Competent Performer
    Windows Vista Access 2007
    Join Date
    Jan 2010
    Location
    Houston, Texas USA
    Posts
    373
    dim ctl as control
    Select Case WasteWaterDisposalTypeID
    Case 1
    for each ctl in me
    if me.ctl.tag=1 them
    me.ctl.visible = false
    else
    me.ctl.visible=true
    end if
    next
    Case else ' to turn all controls visible
    for each ctl in me
    me.ctl.visible=true
    next
    EndSelect

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Setting Field Properties for Numbers
    By Tim Hardison in forum Access
    Replies: 1
    Last Post: 12-09-2009, 06:47 AM
  2. Tab only visible when field = x
    By ecpike in forum Forms
    Replies: 7
    Last Post: 06-08-2009, 04:38 PM
  3. Turn Off Auto Save Record
    By Syntinal in forum Forms
    Replies: 2
    Last Post: 03-01-2009, 11:30 AM
  4. Displaying Query Properties in a Form
    By Bjar in forum Programming
    Replies: 1
    Last Post: 07-16-2008, 07:51 AM
  5. Setting combo box properties
    By rathfam4 in forum Programming
    Replies: 1
    Last Post: 12-28-2005, 02:27 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums