If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > PC based Database Applications > Microsoft Access > Hide/Unhide Labels on Access form base on combo box selection

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 02-08-12, 22:20
VCALI VCALI is offline
Registered User
 
Join Date: Feb 2012
Posts: 1
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
Reply With Quote
  #2 (permalink)  
Old 02-08-12, 23:14
jstpierre jstpierre is offline
Registered User
 
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....
Reply With Quote
  #3 (permalink)  
Old 02-09-12, 08:08
CeejayDBF CeejayDBF is offline
Registered User
 
Join Date: Mar 2010
Posts: 84
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
Reply With Quote
  #4 (permalink)  
Old 02-09-12, 11:16
weejas weejas is offline
Registered User
 
Join Date: Sep 2006
Location: Surrey, UK
Posts: 448
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.
Reply With Quote
  #5 (permalink)  
Old 02-09-12, 13:05
pbaldy pbaldy is offline
Registered User
 
Join Date: May 2005
Location: Nevada, USA
Posts: 2,475
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
Reply With Quote
Reply

Tags
access labels, form, vba access

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On