Results 1 to 7 of 7
  1. #1
    prawln is offline Novice
    Windows 7 32bit Access 2003
    Join Date
    Mar 2011
    Posts
    7

    Textbox/label Visible


    Hey guys needs some help with making labels and textboxs visable and not visable when selecting different words in a bombo box.

    Heres what I have at the moment. Im using 2003

    Private Sub Type_AfterUpdate()
    If Form_Actionreg.Type = "Software" Then
    Form_Actionreg.Workstation.Visible = True
    Form_Actionreg.Workstation_Label.Visible = True
    Form_Actionreg.Modelw.Visible = True
    Form_Actionreg.Modelw_Label.Visible = True
    Form_Actionreg.Comments.Visible = True
    Form_Actionreg.Comments_Label.Visible = True
    Form_Actionreg.Software.Visible = True
    Form_Actionreg.Software_Label.Visible = True

    Else

    Form_Actionreg.Workstation.Visible = False
    Form_Actionreg.Workstation_Label.Visible = False
    Form_Actionreg.Modelw.Visible = False
    Form_Actionreg.Modelw_Label.Visible = False
    Form_Actionreg.Comments.Visible = False
    Form_Actionreg.Comments_Label.Visible = False
    Form_Actionreg.Software.Visible = False
    Form_Actionreg.Software_Label.Visible = False

    End If

    If Form_Actionreg.Type = "Install" Then
    Form_Actionreg.Workstation.Visible = True
    Form_Actionreg.Workstation_Label.Visible = True
    Form_Actionreg.Modelw.Visible = True
    Form_Actionreg.Modelw_Label.Visible = True
    Form_Actionreg.Asset.Visible = True
    Form_Actionreg.Asset_Label.Visible = True
    Form_Actionreg.Serial.Visible = True
    Form_Actionreg.Serial_Label.Visible = True
    Form_Actionreg.ActionRequired.Visible = True
    Form_Actionreg.ActionRequired_Label.Visible = True
    Form_Actionreg.ActionTaken.Visible = True
    Form_Actionreg.ActionTaken_Label.Visible = True

    Else
    Form_Actionreg.Workstation.Visible = False
    Form_Actionreg.Workstation_Label.Visible = False
    Form_Actionreg.Modelw.Visible = False
    Form_Actionreg.Modelw_Label.Visible = False
    Form_Actionreg.Asset.Visible = False
    Form_Actionreg.Asset_Label.Visible = False
    Form_Actionreg.Serial.Visible = False
    Form_Actionreg.Serial_Label.Visible = False
    Form_Actionreg.ActionRequired.Visible = False
    Form_Actionreg.ActionRequired_Label.Visible = False
    Form_Actionreg.ActionTaken.Visible = False
    Form_Actionreg.ActionTaken_Label.Visible = False


    End If

    End Sub

  2. #2
    NoellaG's Avatar
    NoellaG is offline VIP
    Windows 7 Access 2010 (version 14.0)
    Join Date
    Jun 2010
    Location
    Belgium
    Posts
    1,044
    Hi,

    I suppose the question is how to optimize the code?
    In such cases I use the tag property of the form controls, something like:

    for each ctl in me.controls
    if len(ctl.tag) > 0 then
    Ctl.visible = (Instr(ctl.tag, me.type) > 0)
    end if
    next ctl

    All you have to do then is to write in the tag value all type values for which the control has to be visible.

    succes
    NG

  3. #3
    khalid's Avatar
    khalid is offline MS-Access Developer
    Windows 7 64bit Access 2010 64bit
    Join Date
    Mar 2010
    Location
    Kuwait
    Posts
    244
    Hi,

    you want to get the control on your form to visible and un-visible based on your combo value???

    The better way i to use the select case statement:

    Select Case comboValue
    Case "case1"
    .....
    .....
    Case "case2"
    .....
    .....
    Case "casen"
    .....
    .....
    Case Else
    strMsg = “Unhandled Error: “ & Err.Description
    End Select

    so your code could be:

    Private Sub Type_AfterUpdate()

    Select Case Type.value

    Case "Software"

    Form_Actionreg.Workstation.Visible = True
    Form_Actionreg.Workstation_Label.Visible = True
    Form_Actionreg.Modelw.Visible = True
    Form_Actionreg.Modelw_Label.Visible = True
    Form_Actionreg.Comments.Visible = True
    Form_Actionreg.Comments_Label.Visible = True
    Form_Actionreg.Software.Visible = True
    Form_Actionreg.Software_Label.Visible = True

    Case "Install"

    Form_Actionreg.Workstation.Visible = True
    Form_Actionreg.Workstation_Label.Visible = True
    Form_Actionreg.Modelw.Visible = True
    Form_Actionreg.Modelw_Label.Visible = True
    Form_Actionreg.Asset.Visible = True
    Form_Actionreg.Asset_Label.Visible = True
    Form_Actionreg.Serial.Visible = True
    Form_Actionreg.Serial_Label.Visible = True
    Form_Actionreg.ActionRequired.Visible = True
    Form_Actionreg.ActionRequired_Label.Visible = True
    Form_Actionreg.ActionTaken.Visible = True
    Form_Actionreg.ActionTaken_Label.Visible = True

    End Select
    End Sub

    Please note that you have to make your above controls set to Visible = False in onCurrent Event of the form so all your controls will remain hidden until you choose any option from the combobox.

    Also avoid to naming the reserved words like type etc for your controls on the form, using so would create errors while executing.

  4. #4
    NoellaG's Avatar
    NoellaG is offline VIP
    Windows 7 Access 2010 (version 14.0)
    Join Date
    Jun 2010
    Location
    Belgium
    Posts
    1,044
    True,

    but select case still leaves a long code, using the tag property only takes a few lines of code and whenever a new control or Type value is added, you don't have to change the code, only set the tag properties right.

    greetings
    NG

  5. #5
    khalid's Avatar
    khalid is offline MS-Access Developer
    Windows 7 64bit Access 2010 64bit
    Join Date
    Mar 2010
    Location
    Kuwait
    Posts
    244
    but the OP want to use the if conditions based on the combo box selection...

  6. #6
    NoellaG's Avatar
    NoellaG is offline VIP
    Windows 7 Access 2010 (version 14.0)
    Join Date
    Jun 2010
    Location
    Belgium
    Posts
    1,044
    That's why those values are used to write in the tag value. For instance if the control should be visible when tthe type combo is "Software" and/or "Install", gthe tag value will contain "Software,Install". if the control should be visible for "Software" but not "Install" the tag only contains "Software"


    greetings
    NG

  7. #7
    prawln is offline Novice
    Windows 7 32bit Access 2003
    Join Date
    Mar 2011
    Posts
    7
    Ok so I've used the case statement but now it makes the change to every record not just the selected one on the continuousformview

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

Similar Threads

  1. Replies: 2
    Last Post: 01-06-2011, 04:38 AM
  2. variable NOT visible -Please help
    By iamraja5 in forum Programming
    Replies: 10
    Last Post: 11-07-2010, 11:02 AM
  3. Invisible/visible box
    By teirrah1995 in forum Forms
    Replies: 4
    Last Post: 10-03-2010, 02:45 AM
  4. Replies: 5
    Last Post: 01-29-2010, 11:09 AM
  5. Tab only visible when field = x
    By ecpike in forum Forms
    Replies: 7
    Last Post: 06-08-2009, 04:38 PM

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