• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 318
  • Last Modified:

How to reference the Tag of a custom button on a shortcut menu (Access2000)

I have a form with a textbox (memo) that is tied to a shorcut menu with custom buttons.  

How do I reference the tag on the custom button when it gets clicked??
  • 3
1 Solution
DatabaseMX (Joe Anderson - Microsoft Access MVP)Database ArchitectCommented:
You mean like this:

Private Sub Command3_Click()

    Dim sTag As String
    sTag = Me.Command3.Tag
End Sub


Scott McDaniel (Microsoft Access MVP - EE MVE )Infotrakker SoftwareCommented:
I believe it's like this:


If the Button is on a SubMenu, you'll have to work down through those as well, using the same basica syntax.

You can also use the FindControl method with Recursive = True to have VBA locate it for you:


This link might help:

Working with commandbars:

shaun37Author Commented:
I've tried to make each of your suggestions work but it isn't happening.  I'm attaching a code snippet and a sample db.   SampleDb.mdb
Function TagThis()
Dim ctl As Control
Dim StartPos As Long
Dim PostInsert As String
Dim PreInsert As String

Set ctl = Screen.ActiveControl
StartPos = Forms!frmSample.txtMemo.SelStart

  If Not IsNull(ctl) Then
    PreInsert = Left(ctl, StartPos)
    PostInsert = Right(ctl, Len(ctl) - Len(PreInsert))
   'Instead of:
    ctl = PreInsert & "<p>" & PostInsert
   'I would like:
   'ctl = PreInsert & [the selected custom command button TAG here] & PostInsert
  End If
 ctl.SelLength = 0
 Forms!frmSample.txtMemo.SelStart = StartPos
End Function

Open in new window

shaun37Author Commented:
Increasing points - really need someone to take a second look....
shaun37Author Commented:
  Wait!!  It just worked!  The problem was that I had the value of the tag set the same as the name of the tag control.  It was looking for a tag called "<p>" equal to the value of "<p>" and it didn't like that.  When I changed the the tag name to "MyTag" it worked beautifully.

I've been looking at this for tool long.  Thank you kindly.  They're all yours.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now