Results 1 to 5 of 5
  1. #1
    Join Date
    Feb 2012
    Posts
    1

    Unanswered: Hide/Unhide Labels on Access form base on combo box selection

    Hello all first off I've searched the site over and over for situations similar to mine however I've been working with computers and applications long enough to know that one shoe doesn't fit them all.

    That being said......I'm working on a database for a security forces squadron (using access 2007). One feature that i'm adding is a notification matrix that will hide/unhide labels based on the combo list selection.

    I'm trying to use If/Then statements. There are several different combinations of labels that will be hiding/unhiding, so I realize that the VBA may be long but i'm working with two of the labels now to get a feel for how the code is suppose to be set. So here it is:

    Take a look and let me know what i'm doing wrong. Also for the default visibility for the labels themselves should it be yes or no?

    Thanks for everyone's time and help in advance.
    VCALI

    Private Sub MatrixCategory_AfterUpdate()
    If Me![MatrixCategory] = "Aggravated Assault" Then
    Me.Label30.Visible = True
    Me.Label32.Visible = True
    Me.Label33.Visible = True
    Me.Label34.Visible = True
    Me.Label36.Visible = True
    Me.Label37.Visible = True
    Me.Label38.Visible = True
    Me.Label39.Visible = True
    Me.Label40.Visible = True
    Me.Label43.Visible = True
    Me.Label44.Visible = True
    Me.Label45.Visible = True
    Else
    Me.Label30.Visible = False
    Me.Label32.Visible = False
    Me.Label33.Visible = False
    Me.Label34.Visible = False
    Me.Label36.Visible = False
    Me.Label37.Visible = False
    Me.Label38.Visible = False
    Me.Label39.Visible = False
    Me.Label40.Visible = False
    Me.Label43.Visible = False
    Me.Label44.Visible = False
    Me.Label45.Visible = False
    End If

    If Me![MatrixCategory] = "Animal Control (Bite & Quarantine)" Then
    Me.Label30.Visible = True
    Me.Label33.Visible = True
    Me.Label37.Visible = True
    Me.Label40.Visible = True
    Me.Label45.Visible = True
    Me.Label46.Visible = True
    Me.Label47.Visible = True
    Else
    Me.Label30.Visible = False
    Me.Label33.Visible = False
    Me.Label37.Visible = False
    Me.Label40.Visible = False
    Me.Label45.Visible = False
    Me.Label46.Visible = False
    Me.Label47.Visible = False
    End If
    End Sub

  2. #2
    Join Date
    Nov 2011
    Location
    Currently in Kabul Afghanistan
    Posts
    47
    Where is the top half of the declaration, for instance :
    dim mySQL As string
    so if the client selects a value from a value list in one of the Labels [Matrix Category]
    then labels 30 thru 45 are set to True (show) where more selections can be made. If Another value is selected then the other labels are True but not the first set. Correct?

    You are examining a string (text) I think you are missing a single quote mark somewhere ' for encapsulation at the on your first line. You may also have to declare all of the selections in the [Matrix Category] as variables.

    Is you form based on a query?

    I know the second I post this, I am going to be made to look like a moron....but I am going to follow the feed. I am also learning.

    Thanks and lets see what the real experts have to say....

  3. #3
    Join Date
    Mar 2010
    Posts
    88
    Not a "real expert" but might be able to help. First off, what errors or bad consequences are you getting when you use this code?

    Second, what are you actually storing in [MatrixCategory] ? If it is defined as a Number with a relationship into a lookup table of possible values, then it will contain "1", "2", "3" etc (as numbers), not the string. In which case your

    If [MatrixCategory] = "Whatever" ... will never be true.

    You need either to store the string (not a number), or to compare with a lookup of the string into what I presume is a table of possible values.

    There is also a small shortcut in code size available to you:

    dim ShowAggravated as boolean
    ShowAggravated = ([MatrixCategory] = "Whatever")
    Me.Label30.Visible = ShowAggravated
    Me.Label32.Visible = ShowAggravated

    Hope this helps

  4. #4
    Join Date
    Sep 2006
    Location
    Surrey, UK
    Posts
    994
    Provided Answers: 2
    Just a thought, but you might like to investigate the Tag property of the labels. If you know in advance all the permitted values of MatrixCategory, and which labels need to be displayed for each one, you can write the code to compare the selected category with each label's tag value, and set its visibility accordingly.
    That might be too much like taking a sledgehammer to hazelnut, though.
    10% of magic is knowing something that no-one else does. The rest is misdirection.

  5. #5
    Join Date
    May 2005
    Location
    Nevada, USA
    Posts
    2,888
    Provided Answers: 6
    I'll point out the logical flaw in your code. If you stay with this method (rather than the tag or some other method), you want to use either an ElseIf structure or probably better Select/Case. As you have it, you test each possibility independently, so the final test will decide everything. Given your example, if the selection was "Aggravated Assault", Label30 should be visible. Because of the structure of your code, it will fail the test for "Animal Control (Bite & Quarantine)" and Label30 will not be visible.
    Paul

Tags for this Thread

Posting Permissions

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