right click menu in popup form on access 2010 (1 Viewer)

skakooli2

New member
Local time
Today, 17:39
Joined
Dec 11, 2013
Messages
2
Hi all.
I'm new to this great forum.
I'm trying to do right click menu on listbox.
currently i'm trying to implement a right click menu which will show a simple messege box.

My problem is that the list box is on a pop up form which opened up maximized. Now when i'm right clicking on the list box i see the right click menu but when i'm clicking on one of the menu options, nothing happenning (it seems that it don't go to the function as it should). i've also putted breakpoints on the function but it never tips.

It's important to mention that if i'm setting the form popup option to no the right click menu works perfectly (when i'm clicking on one of the options i see its matching messege box).

I'm running the following vba code:

This is the mouse up event handler for my list box:

Private Sub Song_List_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)

' 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
'DoCmd.CancelEvent
CommandBars("MyListControlContextMenu").ShowPopup
End If
End Sub

setting up the "SetUpContextMenu" sub:

Public Sub SetUpContextMenu()
' Note: This requires a reference to Microsoft Office Object Library
Dim combo As CommandBarControl

' 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"
combo.SetFocus
combo.Visible = True
End With

End Sub

setting up the all 3 function which shows different messege boxes on click:

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

Public Function LookupDetailsFunction() As String

LookupDetailsFunction = "Hello World!"

MsgBox LookupDetailsFunction, vbInformation, "Notice!"

End Function

Public Function DeleteRecordFunction()

' If Not IsNull(Forms!MyFormName.Controls("Song_List").Column(0)) Then
MsgBox "Record Deleted"
' End If

End Function
 

JHB

Have been here a while
Local time
Today, 16:39
Joined
Jun 17, 2012
Messages
7,732
I don't think there is anything you can do about it, if you decided to open the form as a pop up form.
And you can only set/change the form's pop up property in design view.
 

MarkHolahan

New member
Local time
Today, 10:39
Joined
Mar 18, 2015
Messages
1
Put your public functions for your pop up in their own module.

HTH.

-Mark Holahan
 

Users who are viewing this thread

Top Bottom