Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations John Tel on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Get tag value from Label in OnClick Procedure

Status
Not open for further replies.

SockMonkey

IS-IT--Management
Mar 6, 2000
41
US
Here is a tricky issue I have been trying to overcome.

I am using field labels at the top of a continuous form to sort the records in the form.

Private Sub LabelName_OnClick()
Sort "fieldName"
End Sub
Private Sub LabelName_OnDoubleClick()
Sort "fieldName", " DESC"
End Sub

If have the sub
Private Sub Sort(fldName As String, Optional SortOrd As String)
Me.OrderBy = ""
Me.OrderBy = fldName & SortOrd
Me.OrderByOn = True
End Sub

The issue is that I would like to get the corresponding field name automatically from the labels tag when the even OnClick for that label is run.
so in essence the procedure would look like this:

Private Sub LabelName_OnClick()
Dim strFieldName as String
strFieldName Me.acLabel.tag
Sort strFieldName
End Sub

However, we all know that you can not get the labels tag value in this method.

Bottom line, how can I get that value?

Thanks in advance for any suggestions.
 
Instead of using Labels why don't your create some Command Buttons and put them in the Form Header above each of your columns. Then you can execute VBA code from the OnClick of each button. Bob Scriver
 
The following is an example of what I posted earlier:
Private Sub btnID_Number_Click()
Sort Mid$(Me.btnID_Number.Name, 4)
End Sub

I create a command button above each column in a Continuous form and put them in the Form Header area. Each was named in the following manner.
Column Datafield name: ID_Number
Command Button control name: btnID_Number

Each of the command buttons are named "btn" & (Date Field Name). This way the code above will always strip off the "btn" leaving just the name of the column data field name.

This may help you in your situation.

Bob Scriver
 
Thanks for the suggestion.
However I have tried the command buttons but you then have no control of the background color of the button

I do have a similar procedure for stripping the field name from the label.name but alas I can not get that to work either since there seems to be no way in VB to reference the currently active label that you are clicking on.
 
You can control the color of the Command Buttons by making them transparent. Then make a Box the same size as the command button and give it a .backcolor of your choosing. Create a small label for the psuedo button caption.

Now place them in this order: Box in the back, Label on top of box, and transparent button on top of the label. The CommandButtons event procedures are still all available so you can put your code there and you can change the .backcolor of your box behind it to meet your needs. Turn in to red when you click to sort and turn it back to grey when you choose another colomn for sort.

Give that a try. Bob Scriver
 
try this change your sub sort to
function sort(Optional SortOrd As String)
Me.OrderBy = ""
Me.OrderBy = active.control.tag & SortOrd
Me.OrderByOn = True
end function

set the on Click to =sort()
set the on DoubleClick to =sort(" DESC")
set the lables tag to the field name
 
Thanks Bob for your input on this.
Seems like I would have to do the double work with a command button & labelbox to get what should be doable with just one of those.

I think I will stick with using my labels for sorting and leave it at that.


Robert

...sometimes what you think should be easier really isn't!
 
Did you try pwise's suggestion. It sounds like a viable solution without having to code specifically to a particular label?

I have a question through. You stated in your post that you were using a continuous form and using the labels that are associated with the column. How are you creating this situation. The label of a textbox in a continuous form stays in the form and I can't seem to get it to move to the Form Header and still stay linked. Let me know if you can advise me as to how you have done this.

Bob Scriver
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top