SHORT CUT MENU

D

Developerme

In Access 2007 runtime, is there a way to add a short-cut menu on forms that
will show Copy and Paste function? Or is the only viable means to go with
keyboarding it? Thanks.
 
A

Albert D. Kallal

How to do this is explained here:

http://office.microsoft.com/en-us/access/HA102825091033.aspx?pid=CH100621911033


For cut + edit + paste, your macro look like:

Macro Name Action Command
Cut RunCommand Cut
Copy RunCommand Copy
Paste RunCommand Paste

Simply Save the above macro as MyMenu

Then create a macoro that calls the above

eg:
Action Menu Name Menu Macro name Status Bar text
AddMenu MyRightClick MyMenu My Edit

save the above as mEdit

Then, in the forms property sheet, simply set the shortcut menu as mEdit
 
D

Developerme

Thanks but I already located that information. However, MS Access 2007 will
not allow these functions and creates an error everytime.
 
A

Albert D. Kallal

Developerme said:
Thanks but I already located that information. However, MS Access 2007
will
not allow these functions and creates an error everytime.

I not sure why you having an error... just tried my example and it worked
fine for me......

So, access does allow these functions, and each time it does not create an
error for me.

Does other code and/or macros run fine in your application in addition to my
suggested macro?
 
D

Developerme

I know it works on Access 2003. But not on Access 2007. I tried again, fresh
coding and same result in Access 2007.
 
D

Dale Fye

I've been building my shortcut menus via code for a number of years. I find
this to be more flexible and portable than the old menu customization, and
have not tried the new macros in 2007.

All I do is call TextMenu when my application loads, then set the
shortcutmenubar to "MyTextMenu" for the form or control of interest.

Here is a sample of my code:

Public Sub TextMenu(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 = "&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 = "&Find"
.Tag = "Find"
.OnAction = "=fnTextFind()"
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 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 CmdBarExists(BarName As String) As Boolean

Dim intControls

On Error Resume Next
intControls = CommandBars(BarName).Controls.Count
If Err.Number = 0 Then
CmdBarExists = True
Else
CmdBarExists = False
End If

End Function
Public Sub DeleteCmdBar(BarName As String)

Dim intLoop As Integer

'If an error is generated, it is because the command bar doesn't exist,
ignore it
On Error GoTo DeleteCmdBar_Error
CommandBars(BarName).Delete
Exit Sub

DeleteCmdBar_Error:
Err.Clear

End Sub

--
HTH
Dale

email address is invalid
Please reply to newsgroup only.
 
C

ChezMC

When I try and create my macro I don't have all the options for runcommand in
the list and you can't add to the list. The options Cut, Copy and Paste are
not there.
For cut + edit + paste, your macro look like:

Macro Name Action Command
Cut RunCommand Cut
Copy RunCommand Copy
Paste RunCommand Paste

I imported your macros from your example, that you kindly posted, and then I
have the other options available inside your macro. But if I create a new
macro (in your db and any otherdb) these list items and many more are still
not available.

Am I missing some reference file.
Currently I have these
C:\Program Files\Common Files\Microsoft Shared\VBA\VBA6\VBE6.DLL
C:\Program Files\Microsoft Office\Office12\MSACC.OLB
C:\Windows\system32\stdole2.tlb
C:\Program Files\Common Files\Microsoft Shared\VBA\VBA6\VBE6EXT.OLB
C:\PROGRA~1\COMMON~1\MICROS~1\OFFICE12\ACEDAO.DLL

Thanks
 
K

Kim M.

I am having a similar problem. I have created a number of shortcut menus
using macros, and they all work great.

The problem I am having is specifically with the Cut/Copy/Paste commands --
they are simply not listed as RunCommand options in the macro design form!
Can anyone shed light on this? I am using Access 2007.

TIA,
Kim M.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top