Reputation: 36
I have a form called "DetailedCalendar" with the default View "Continuous Forms".
The issue I'm having is that when I Right Click on a record, the context menu appears for the wrong record, in that the record was not selected. I'm getting the ID of the record that was selected prior to the right click.
I saw a similar post called 'Get Current Record on Right-Click CommandBar Menu' but I'm not sure it was clear on what was trying to fix, and there was no clear answer. I'm hoping my description will be a little more informative.
Can I make the right click select the record prior to displaying the shortcut menu?
I tried to use screen
Function LoadApplicationCommandBars() As String
Dim lngReturn as long
MenuChoice = "CalendarDetailContextMenu"
On Error Resume Next
' will cause error '5: Invalid procedure call or argument' if requested CommandBar does not exist
Application.CommandBars(MenuChoice).Delete
On Error GoTo Routine_Err
Set cbrNewMenu = Application.CommandBars.Add(MenuChoice, 5) ' 0=msoBarLeft, 1=msoBarTop, 2=msoBarRight, 3=msoBarBottom, 4=msoBarFloating, 5=msoBarPopup, 6=msoBarMenuBar
Set mnuItem = cbrNewMenu.Controls.Add(msoControlButton)
mnuItem.Style = msoButtonIconAndCaption
mnuItem.Caption = "Edit Row"
mnuItem.OnAction = "=EditRow()"
mnuItem.FaceId = 488
strReturn = 0
Routine_End:
LoadApplicationCommandBars = lngReturn
Exit Function
Routine_Err:
strReturn = Err.Number
Resume Routine_End
End Function
'========================================================================
' from SHORT CUT menu
Public Function EditRow()
MsgBox "LineID=" & Me![ID]
'DoCmd.OpenForm "EditActivities", acNormal, "", "[ID]=" & ID
End Function
'========================================================================
Private Sub Form_Load()
Me.ShortcutMenuBar = "CalendarDetailContextMenu"
End Sub
The closest I've gotten to finding a solution is to use the Form_MouseUp which provides X Y details of where the click occured, but I'm not sure how to use the coordinates to select the record.
Private Sub Form_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
Debug.Print "Form_MouseUp " & Me![ID] & " x=" & X & " y=" & Y
End Sub
I fear there is no solution. Can someone confirm?
Thanks in advance.
Upvotes: 0
Views: 234
Reputation: 36
Ok, so it seems the right click (the non-select button) will not select the record without serious intervention.
So, my best choice is to create a Button that covers the surface of my row, as all the information is read only anyway:
Now when I right click, it will activate the record with the Right Click and the shortcut menu still works. I can't modify the details under the button, but that's ok for most uses of Continuous Forms where inline editing is not usually encouraged.
The other alternative is, to use the left-click and create a Form double click function. Then I can bring up the options relating to the record on a separate form.
Upvotes: 0