Full Version: Using A Wildcard Character In A Label Caption
UtterAccess Discussion Forums > Microsoft® Access > Access Forms
toons
Im about to pull my hair out. This is the current code

CODE
Me("Label").Caption = "*"



I need it to have 2 numerical placeholders so it only changes label captions that are like


CODE
Me("Label" & ##).Caption = "*"



how in the world do I get it to recognize the ## and properly append it to the Label segment of a label caption to match the criteria? I have tried so many combinations and it just wont configure properly and only change labels matching Label##. Please help!
MikeLyons
QUOTE (toons @ May 22 2012, 01:41 PM) *
Im about to pull my hair out. This is the current code

CODE
Me("Label").Caption = "*"



I need it to have 2 numerical placeholders so it only changes label captions that are like


CODE
Me("Label" & ##).Caption = "*"



how in the world do I get it to recognize the ## and properly append it to the Label segment of a label caption to match the criteria? I have tried so many combinations and it just wont configure properly and only change labels matching Label##. Please help!


I'm not sure I follow what you mean by "placeholder".

How have you actually named your label controls on the form? Label01, Label02, etc.?

Mike
CyberCow
What are you ultimately trying to do? If you are needing to alter the contents of all label controls, you can Loop Through Controls

And to place the asterisk character * into a label's caption or other VBA usage, you need to replace the asterisk with the Chr() function.

In your immediate window you can see that ?Chr(42) will render an asterisk.

hope this helps
datAdrenaline
There is no need to use Chr(42) to use the "*" in a Label controls .Caption property...

Me.someLabelControlName.Caption = "*"

works just fine. The "*" is only a special character if the Like operator is being used.
datAdrenaline
>> I need it to have 2 numerical placeholders so it only changes label captions that are like <<

If you are looping controls, then (if I am following you correctly), you will possibly want to do this ...

CODE
    Dim ctl As Control
    
    For Each ctl In Me.Controls
    
        If ctl.Name Like "Label*" And ctl.ControlType = acLabel Then _
            If IsNumeric(Replace(ctl.Name, "Label", "", 1, 1, vbTextCompare)) Then _
                ctl.Caption = "*"
                
    Next

Galaxiom
Sometimes, depending on the situation it can be easier to fake the label using a textbox locked, disabled and with no border.
The advantage is that it can be bound to the form's recordset.
datAdrenaline
... And a little more intuitive (IMO) to work with in code or in objects that may reference the value that is displayed.
toons
ok, all great info. this is what I am trying to accomplish

I have 20 buttons on a "keypad" looking setup on a form. The values on those buttons are tied to a category ID on a main button menu. When I click on a different category, I want it to first reset all the Label captions on those 20 buttons (Label00, 01, 02, etc) before applying the label values associated with the chosen category. I could probably do the loop, but I would imagine there would have to be an easier route so that when I click on a main button all instances of Label## update the value
MikeLyons
QUOTE (toons @ May 23 2012, 05:46 AM) *
ok, all great info. this is what I am trying to accomplish

I have 20 buttons on a "keypad" looking setup on a form. The values on those buttons are tied to a category ID on a main button menu. When I click on a different category, I want it to first reset all the Label captions on those 20 buttons (Label00, 01, 02, etc) before applying the label values associated with the chosen category. I could probably do the loop, but I would imagine there would have to be an easier route so that when I click on a main button all instances of Label## update the value


There's no magic command to update them all at once. You have to implement that code yourself.

Mike
toons
I wound up creating a public function that would loop through the buttons and update them, and having that function called in other events.
datAdrenaline
>> I could probably do the loop, but I would imagine there would have to be an easier route so that when I click on a main button all instances of Label## update ... <<

The code I posted is pretty easy (in my opinion) smirk.gif Also, the only way to modify the .Caption property is through some sort of automation like code/macro. Plus, is the .Caption property is not really a dynamic property, that is where the thoughts of using a text box and possibly using the Control Source property to dynamically control the value. But with that, you are still looking at code to control things -- unless there is more information to the scenario you are not revealing -- like, are the values for the labels stored in a record of a table that is bound to the form and the appropriate record is navigated to when buttons are clicked?

Either way though, I think you will be looking at a code/macro based solution to your quest, and the For..Loop I presented will likely be the framework in which your logic would be applied.
toons
this is what was used

CODE
Public Sub ClearSubMenu()

'Clear all sales item labels to default backcolor (light grey)

Dim vRow As Long, vCol As Long

    For vRow = 0 To 5
        For vCol = 0 To 3
            Me("Label" & vRow & vCol).Caption = "*"    'reset menu item label names
        Next
    Next
    Me.txtPrice = 0

End Sub



in a different event, it calls ClearSubMenu at the proper time to reset all label names before applying the new value. they are captions on buttons, so overlaying a transparent text field would be too busy. there are already 20 buttons which control menu values.
datAdrenaline
I am glad you were able to work out a solution! thumbup.gif
Galaxiom
Keypads can be implimented as a subform using textboxes for both "keys" and "labels".

Moroever the need for a separate control for each key can be avoided by using Continuous Forms.
Columns can be done using a separate instances of the same subform for each column and allocating the key to a column in the RecordSource query of each subform.

This structure would offer a dramatic reduction in the number of procedures.

I would tie the whole thing togther as a Class.
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.