Solved

Access 2010 adding a right Click short cut menu

Posted on 2011-09-19
12
873 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
Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

 
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
 
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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I see at least one EE question a week that pertains to using temporary tables in MS Access.  But surprisingly, I was unable to find a single article devoted solely to this topic. I don’t intend to describe all of the uses of temporary tables in t…
A simple tool to export all objects of two Access files as text and compare it with Meld, a free diff tool.
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 …
With Microsoft Access, learn how to specify relationships between tables and set various options on the relationship. Add the tables: Create the relationship: Decide if you’re going to set referential integrity: Decide if you want cascade upda…

840 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