I have written an application in MS Access 2003. I can run this using Access 2010, however when I open the same 2003 application with the MS Access 2010 Runtime only, I can no longer use the Right Mouse Click in a continuous form (as I can with the full version) to filter by selection or to sort data etc. Has anyone else encountered this situation? Is this a purposeful design of Access 2010? If so, does anyone know why the Right-Click Content Menu is not working? Otherwise – is it a normal part of the Runtime 2010 and my application is the problem?
Ms-access – MS Access 2010 Runtime – Missing Right Mouse Click Context Menu in continuous forms
ms-accessms-access-2010
Related Solutions
First create an _MouseUp
event to execute on the respective control looking to see if the right mouse button was clicked and if so, call the .ShowPopup
method.
Of course this assumes the
Private Sub MyListControlName_MouseUp(ByVal Button As Integer, _
ByVal Shift As Integer, _
ByVal X As Long, ByVal Y As Long)
' Call the SetUpContextMenu function to ensure it is setup with most current context
' Note: This really only needs to be setup once for this example since nothing is
' changed contextually here, but it could be further expanded to accomplish this
SetUpContextMenu
' See if the right mouse button was clicked
If Button = acRightButton Then
CommandBars("MyListControlContextMenu").ShowPopup
End If
End Sub
Since at this point the Command Bar MyListControlContextMenu
is undefined, I define the Menu in a separate module as follows:
Public Sub SetUpContextMenu()
' Note: This requires a reference to Microsoft Office Object Library
Dim combo As CommandBarComboBox
' Since it may have been defined in the past, it should be deleted,
' or if it has not been defined in the past, the error should be ignored
On Error Resume Next
CommandBars("MyListControlContextMenu").Delete
On Error GoTo 0
' Make this menu a popup menu
With CommandBars.Add(Name:="MyListControlContextMenu", Position:=msoBarPopup)
' Provide the user the ability to input text using the msoControlEdit type
Set combo = .Controls.Add(Type:=msoControlEdit)
combo.Caption = "Lookup Text:" ' Add a label the user will see
combo.OnAction = "getText" ' Add the name of a function to call
' Provide the user the ability to click a menu option to execute a function
Set combo = .Controls.Add(Type:=msoControlButton)
combo.BeginGroup = True ' Add a line to separate above group
combo.Caption = "Lookup Details" ' Add label the user will see
combo.OnAction = "LookupDetailsFunction" ' Add the name of a function to call
' Provide the user the ability to click a menu option to execute a function
Set combo = .Controls.Add(Type:=msoControlButton)
combo.Caption = "Delete Record" ' Add a label the user will see
combo.OnAction = "DeleteRecordFunction" ' Add the name of the function to call
End With
End Sub
Since three function have been referenced, we can move on to define these as follows-
getText: Note, this option requires a reference to both the name of the Command Bar menu name as well as the name of the control caption.
Public Function getText() As String
getText = CommandBars("MyListControlContextMenu").Controls("Lookup Text:").Text
' You could optionally do something with this text here,
' such as pass it into another function ...
MsgBox "You typed the following text into the menu: " & getText
End Function
LookupDetailsFunction: For this example, I will create a shell function and return the text "Hello World!".
Public Function LookupDetailsFunction() As String
LookupDetailsFunction = "Hello World!"
MsgBox LookupDetailsFunction, vbInformation, "Notice!"
End Function
DeleteRecordFunction: For this example, I will ensure the control is still valid by checking it against null, and if still valid, will execute a query to remove the record from a table.
Public Function DeleteRecordFunction() As String
If Not IsNull(Forms!MyFormName.Controls("MyListControlName").Column(0)) Then
Currentdb.Execute _
"DELETE * FROM [MyTableName] " & _
"WHERE MyKey = " & Forms!MyFormName.Controls("MyListControlName").Column(0) & ";"
MsgBox "Record Deleted", vbInformation, "Notice!"
End If
End Function
Note: For LookupDetailsFunction
, DeleteRecordFunction
and getText
functions, these must be within a public scope to work correctly.
Finally, the last step is to test the menu. To do this, open the form, right click on the list control and select one of the options from the popup menu.
Optionally button.FaceID
can be utilized to indicate a known office icon to associate with each instance of the menu popup control.
I found Pillai Shyam's work on creating a FaceID Browser Add-In to be very helpful.
Actually the buttons should work in a datasheet view. However in a continuous form in the runtime environment they will NOT be enabled and they will not work.
The simple solution here is add a couple of your own custom buttons to that meuu bar.
Have those buttons call VBA code that simply sets the sort to ascending, or decending.
So, for the a->z buttion, change the on-action to:
=MySortDown()
(Remember to add some new buttons here, don't use the built in one says they'll be disabled - you can use the custom menu editor to copy the graphic images form the original buttons however)
And for the sort descending button, you can use:
=MySortUp()
Then in a standard code module, place the above two functions that will be called and they can be written as follows.
Public Function mySortDown()
Dim f As Form
Dim c As Control
Set f = Screen.ActiveForm
Set c = f.ActiveControl
f.OrderBy = c.ControlSource
f.OrderByOn = True
End Function
Public Function mySortUp()
Dim f As Form
Dim c As Control
Set f = Screen.ActiveForm
Set c = f.ActiveControl
f.OrderBy = c.ControlSource & " DESC"
f.OrderByOn = True
End Function
Followup:
I don’t have a reference for what works. However, during testing you can create a shortcut that allows you to test/run your code as if it is in runtime mode.
Just use:
"C:\Program Files\Microsoft Office\OFFICE11\MSACCESS.EXE"
"c:\program files\RidesXP\RidesXP.mdb" /runtime
The above is on one line in the shortcut (and a space between each line).
As for the datasheet sort buttons not working, no problem. I think it might depend on which buttons you lifted from the built-in ones. Regardless, my sample/example code should work for either case.
Best Answer
The Runtime unfortunately doesn't have context menu enabled, however, you can re-create some of it for your application.
For instance, in mine, I create a basic copy/cut/paste context menu like this:
Just call this code once at the start of your application and the context menu will be available everywhere.
The Need a list of msoControlButton Ids thread on MSDN shows how to similarly add Sorting and filter options.