Solved

Access 2010 adding a right Click short cut menu

Posted on 2011-09-19
12
850 Views
Last Modified: 2012-05-12
Hi

How do I create and add a right click short cut menu to a control in Access 2010?

many thanks
0
Comment
Question by:kenabbott
  • 6
  • 4
  • 2
12 Comments
 
LVL 47

Accepted Solution

by:
Dale Fye (Access MVP) earned 500 total points
ID: 36560991
if you already have the shortcut menu, then you just need to assign it in the controls ShortcutMenu property in the properties dialog.

I you are talking about a "custom menu", I build mine in code.  Attached is a sample of the menu I display in my textboxes.  Paste the attached into a new code module, or into the forms code module if you don't want to make it callable from all forms.  There are a couple of other options in my default version, but those involve other forms.

When your application loads (Splash or Startup form), call the subroutine MenuText.

Then in design view of your form, select the control and set the ShortcutMenu property to "MyTextMenu"

Public Sub MenuText(Optional Reset As Boolean = False)

    Dim cbr As Object
    Dim cbrButton As Object

    'If the commandbar exists, and Reset is false, then exit
    If CmdBarExists("MyTextMenu") Then
        If Reset = False Then
            Exit Sub
        Else
            DeleteCmdBar "MyTextMenu"
        End If
    End If
        
    On Error GoTo TextMenuError

    DoCmd.Hourglass True

    Set cbr = CommandBars.Add("MyTextMenu", BarPopup, , True)

    With cbr

        Set cbrButton = cbr.Controls.Add(ControlButton, , , , True)
        With cbrButton
            .Caption = "&Copy"
            .Tag = "Copy"
            .OnAction = "=fnTextCopy()"
        End With

        Set cbrButton = cbr.Controls.Add(ControlButton, , , , True)
        With cbrButton
            .Caption = "Cu&t"
            .Tag = "Cut"
            .OnAction = "=fnTextCut()"
        End With

        Set cbrButton = cbr.Controls.Add(ControlButton, , , , True)
        With cbrButton
            .Caption = "&Paste"
            .Tag = "Paste"
            .OnAction = "=fnTextPaste()"
        End With

        Set cbrButton = cbr.Controls.Add(ControlButton, , , , True)
        With cbrButton
            .begingroup = True
            .Caption = "&Spell check"
            .Tag = "Spell check"
            .OnAction = "=fnTextSpell()"
        End With

        Set cbrButton = cbr.Controls.Add(ControlButton, , , , True)
        With cbrButton
            .begingroup = True
            .Caption = "&Zoom"
            .Tag = "Zoom"
            .OnAction = "=fnTextZoom()"
        End With
        
    End With

    DoCmd.Hourglass False
    Exit Sub
    
TextMenuError:
    MsgBox Err.Number & vbCrLf & Err.Description, vbInformation + vbOKOnly, "TextMenu error:"
    
End Sub

Public Function fnTextCopy()

    Dim frm As Form
    Dim ctrl As Control
    
    Set frm = Screen.ActiveForm
    Do While frm.ActiveControl.ControlType = acSubform
        Set frm = frm.ActiveControl.Form
    Loop
    Set ctrl = frm.ActiveControl
    
    If ctrl.SelLength = 0 Then
        ctrl.SelStart = 0
        ctrl.SelLength = Len(ctrl.Text)
    End If
    
    DoCmd.RunCommand acCmdCopy
        
End Function

Public Function fnTextCut()

    Dim frm As Form
    Dim ctrl As Control
    
    Set frm = Screen.ActiveForm
    Do While frm.ActiveControl.ControlType = acSubform
        Set frm = frm.ActiveControl.Form
    Loop
    Set ctrl = frm.ActiveControl
    
    If ctrl.SelLength = 0 Then
        ctrl.SelStart = 0
        ctrl.SelLength = Len(ctrl.Text)
    End If
    
    DoCmd.RunCommand acCmdCut
        
End Function

Public Function fnTextPaste()

    Dim frm As Form
    Dim ctrl As Control
    
    On Error GoTo TextPasteError
    
    Set frm = Screen.ActiveForm
    Do While frm.ActiveControl.ControlType = acSubform
        Set frm = frm.ActiveControl.Form
    Loop
    Set ctrl = frm.ActiveControl
    
    DoCmd.RunCommand acCmdPaste
    Exit Function
TextPasteError:
    If Err.Number = 2046 Then
        Resume Next
    Else
        DisplayError "Error encountered while attempting to paste text!"
    End If
End Function
Public Function fnTextSpell()

    Dim frm As Form
    Dim ctrl As TextBox
    
    On Error GoTo SpellError
    
    Set frm = Screen.ActiveForm
    Do While frm.ActiveControl.ControlType = acSubform
        If Application.Version > 11 And Application.Build < 6322 Then
            MsgBox "Unable to spell check this item!"
            Exit Function
        Else
            Set frm = frm.ActiveControl.Form
        End If
    Loop
    
    Set ctrl = frm.ActiveControl
    With ctrl
        
        If ctrl.SelLength = 0 Then
            ctrl.SelStart = 0
            ctrl.SelLength = Len(ctrl.Text)
        End If
    
    End With
    
    If ctrl.SelLength > 0 Then DoCmd.RunCommand acCmdSpelling
    Exit Function

SpellError:
    DisplayError "Error encountered by spell checker"
    
End Function

Public Function fnTextZoom()
    
    Dim Ctrl As Control
    Dim frm As Form
    Dim rs As DAO.Recordset
    Dim strCriteria As String

    Set frm = Screen.ActiveForm
    While frm.ActiveControl.ControlType = acSubform
        Set frm = frm.ActiveControl.Form
    Wend
    Set rs = frm.RecordsetClone
    Set Ctrl = Screen.ActiveControl

    DoCmd.RunCommand acCmdZoomBox
    
End Function

Open in new window

0
 
LVL 75
ID: 36561167
"How do I create and add a right click short cut menu to a control in Access 2010?"
Other than doing this in code, you can't.  This is highly unfortunate that the Custom menu tool was removed from A2010 (and A2007).

mx
0
 

Author Comment

by:kenabbott
ID: 36561205
"This is highly unfortunate that the Custom menu tool was removed from A2010 (and A2007)."

That was what was confusing me because I was sure I had used it in the distant past.  What was the point of removing it???
0
 
LVL 75
ID: 36561224
" What was the point of removing it???"
Absolutely none in my book.  Since previous menus, toolbars and right click shortcuts (from <=A2003) ARE still supported in A2010, the is no good reason that tool could not still be present ... in addition to the Ribbon paradigm.

Sad ...

mx
0
 

Author Comment

by:kenabbott
ID: 36561468
" Since previous menus, toolbars and right click shortcuts (from <=A2003) ARE still supported in A2010"

So presumably this means that I could run an A2003 db in 2010 and any custom right click menu would work but there is no way of importing them into a A2010 db??
0
 
LVL 75
ID: 36561520
"So presumably this means that I could run an A2003 db in 2010 and any custom right click menu would work"
Definitely.

"but there is no way of importing them into a A2010 db??"
Not that I've seen.

Also ... fyi ... you should check out this site at some point ... everything Ribbon:

http://www.accessribbon.de/en

I contacted him re adding on a tool to create Right Click menus ... but he said no time at the present.

mx

0
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 47

Expert Comment

by:Dale Fye (Access MVP)
ID: 36561529
I have not tried, and don't have 2010 available at the moment, and cannot remember the names for yet another user interface.  It used to be that you could import these custom menus using the Get External Data option.  In 2007, if you click the "Options" button on the Import Objects dialog, there is a checkbox for "Menus and Toolbars".  That is the first place I would start.
0
 
LVL 75
ID: 36561608
Dale ... you're RIGHT!  Man, I missed that one. That works in A2010 also. Once you select an MDB and the dialog opens to select objects, you can just select Options>>Menus & Toolbars ... and it will import the 'bars' onto the Add-Ins Ribbon.

That is good news to some extent.  It provides a workaround to still create custom bars in A2003 and them get them into A2010.  I need to test what happens if ... say I need to add an additional item to a right click menu ... then import into A2010 ... will get dups of everything already there ... plus the new added item ...?

mx
0
 
LVL 47

Expert Comment

by:Dale Fye (Access MVP)
ID: 36561669

Joe,

You should also be able to use code similar to what I provided above to add controls to those "saved" commandbars, although I have never done this, and don't know whether those additions would also be saved.

I do know that the commandbars I create with the code I posted above must be recreated each time my application loads.
0
 
LVL 75
ID: 36561682
I imagine that works.  Just that ... it was soooooooooooooooooo EASY in <=A2003 to do this ... no code ... to create super cool 'bars', of which I have 100's.

mx
0
 
LVL 47

Expert Comment

by:Dale Fye (Access MVP)
ID: 36561714
Joe,  

You could write an add-in, that we could all use.

I'm sure there has to be a way to make these command bars "permanent", I just have not figured out how to do it yet, so I continue to use the code method.  

I've got versions that use combo boxes and textboxes as well.
0
 
LVL 75
ID: 36561940
Yes, maybe I $$$could$$$ :-)

But they ... lets get the Ribbon guy to do this ... a tool within A2010 to create right clicks ... since he is already in this mode.

It might be possible to leverage something from this:

http://www.lebans.com/commandbars.htm

?
0

Featured Post

Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

Join & Write a Comment

This article is a continuation or rather an extension from Cascading Combos (http://www.experts-exchange.com/A_5949.html) and builds on examples developed in detail there. It should be understandable alone, but I recommend reading the previous artic…
In the article entitled Working with Objects – Part 1 (http://www.experts-exchange.com/Microsoft/Development/MS_Access/A_4942-Working-with-Objects-Part-1.html), you learned the basics of working with objects, properties, methods, and events. In Work…
Basics of query design. Shows you how to construct a simple query by adding tables, perform joins, defining output columns, perform sorting, and apply criteria.
In Microsoft Access, learn how to use Dlookup and other domain aggregate functions and one method of specifying a string value within a string. Specify the first argument, which is the expression to be returned: Specify the second argument, which …

760 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now