• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 470
  • Last Modified:

Right Click on form not working

I have some code that is troubling me. It works on some forms and on others it is not working.

Trying to open a right click menu and add a status change. When I right click on tvSC I get the menu but when I click on a choice it just goes away and does not open the form to add a new status change.

I believe that under the CreateMenu that choosing Add Status Change should go to the pcAdd and then open the frmBenefitsStatusChangeAddNew but it isn't. It is just bypassing everything altogether. I have other forms that work properly so I'm confused. Any thoughts?


Public Sub DeleteMenu(MenuName As String)
    '  Procedure is used to delete a toolbar
    Dim mBar As CommandBar
    On Error Resume Next
    Set mBar = CommandBars(MenuName)
    mBar.Delete
End Sub

Open in new window


Private Sub tvSC_MouseDown(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Long, ByVal Y As Long)
    '  Open a sub menu for the user
    Dim strMenuName As String
    
    strMenuName = "StatusChange"
    If Button = acRightButton Then
        Call DeleteMenu(strMenuName)
        Call CreateMenu(strMenuName)
    End If
End Sub

Private Sub CreateMenu(MenuName As String)
    '  Procedure is used to create the submenu
    Dim X As CommandBar
    Dim Y As CommandBarButton
    Dim z As CommandBarComboBox
    
    Set X = CommandBars.Add(MenuName, msoBarPopup)
    
    
    Set Y = X.Controls.Add(msoControlButton)
    With Y
        .Caption = "Add Status Change"
        .OnAction = "=Forms!frmbenefitsstatuschangemaintain.ManageStatusChange(" + "'" + "pcAdd" + "'" + ")"
        'Forms!frmDBAjobClassCode.AddJobClassCode (JCC)
    End With
    
    
    If bTreeFilter = False Then
        '  Allow the user to filter the tree
        Set z = X.Controls.Add(msoControlEdit)
        With z
            .Caption = "Filter"
            .Text = "Enter ID"
            .OnAction = "=Forms!frmbenefitsstatuschangemaintain.ManageStatusChange(" + "'" + "pcFilter" + "'" + ")"
        End With
    Else
        '  User needs to be able to remove the filter
        With Y
            .Caption = "Remove Filter"
            .OnAction = "=Forms!frmbenefitsstatuschangemaintain.ManageStatusChange(" + "'" + "pcFilter" + "'" + ")"
        End With
    End If
    
    
    intMenuCount = 0
    X.ShowPopup
    
    
End Sub

Open in new window


Public Function ManageStatusChange(SCText As String)
    Dim X As CommandBar
    Dim yButton As CommandBarControl
    Dim z As CommandBarComboBox
    Dim strFilterText As String
    
    
    If intMenuCount > 0 Then
        GoTo NoAction
    End If
    intMenuCount = intMenuCount + 1
    
    Select Case SCText
        Case "pcAdd"
            Call AddNewStatusChange
        Case "pcFilter"
            If bTreeFilter = False Then
                '  Apply the filter
                For Each X In Application.CommandBars
                    If X.Name = "StatusChange" Then
                        For Each yButton In X.Controls
                            With yButton
                                If .Caption = "Filter" Then
                                    Set z = yButton
                                    If IsNull(z.Text) = False Then
                                        strFilterText = z.Text
                                        If Len(strFilterText) > 0 Then
                                            strFilterID = strFilterText
                                            bTreeFilter = True
                                            Call RefreshTree
                                        End If
                                    End If
                                End If
                            End With
                        Next yButton
                    End If
                Next X
                
            Else
                '  remove the filter
                bTreeFilter = False
                Call RefreshTree
            End If
        
        
    End Select

    
NoAction:
    Exit Function
End Function

Open in new window


Private Sub AddNewStatusChange()
    '  Procedure opens the form to allow the add of a new status Change
    '  Data is passed as the following string
    '  ID~EffectiveDate~FromTotalHours~ToTotalHours~AnnualSalary
    Dim strCriteria As String
    Dim i As Integer
    Dim strID As String
    Dim dtmEffective As Date
    Dim sngFrom As Single
    Dim sngTo As Single
    Dim sngAnnual As Single
    Dim sngAnnualOld As Single
    Dim lngSCID As Long
    
    DoCmd.Openform "frmBenefitsStatusChangeAddNew", acNormal, , , , acDialog
    
    If varPassData <> "pcNone" Then
        '  Clear the data
        Call ClearFields(True)
        '  Parse the data and add
        strCriteria = CStr(varPassData)
        i = InStr(strCriteria, "~")
        '  ID
        strID = Left(strCriteria, i - 1)
        strCriteria = Mid(strCriteria, i + 1)
        
        '  Effective Date
        i = InStr(strCriteria, "~")
        dtmEffective = CDate(Left(strCriteria, i - 1))
        strCriteria = Mid(strCriteria, i + 1)
        
        '  From Hours
        i = InStr(strCriteria, "~")
        sngFrom = CSng(Left(strCriteria, i - 1))
        strCriteria = Mid(strCriteria, i + 1)
        
        '  To Hours
        i = InStr(strCriteria, "~")
        sngTo = CSng(Left(strCriteria, i - 1))
        strCriteria = Mid(strCriteria, i + 1)
        
        '  New Annual
        i = InStr(strCriteria, "~")
        sngAnnual = CSng(Left(strCriteria, i - 1))
        
        
        '  Old Annual
        sngAnnualOld = CSng(Mid(strCriteria, i + 1))
        
        '  Add New record to the table - get the StatusChangeID
        lngSCID = AddNewSCRecord(strID, dtmEffective, sngFrom, sngTo, sngAnnual, sngAnnualOld)
        
        
        
        '  Delete existing nodes
        Call DeleteNodes
        
        '  refresh the status change tree
        'TreeSC.Close
        'Set TreeSC = Nothing
        'Call GetStatusChanges(strDataMode)
        
        TreeSC.Requery
        
        Call LoadTree
        
        
        '  Highlight new node and display the record
        Call HighlightNode(lngSCID)
        
        '  Display the data
        Call DisplayData(lngSCID)
        
    End If
    
End Sub

Open in new window

0
dminx13
Asked:
dminx13
  • 4
  • 2
1 Solution
 
Scott McDaniel (Microsoft Access MVP - EE MVE )Infotrakker SoftwareCommented:
If you click on Add Status Change in the menu, you're firing this:

Forms!frmbenefitsstatuschangemaintain.ManageStatusChange(" + "'" + "pcAdd" + "'" + ")"

And you want to pass in a value of "pcAdd", but I believe you're passing "  'pcAdd'  " (with the single quotes). Try doing this:

Forms!frmbenefitsstatuschangemaintain.ManageStatusChange('pcAdd')

or

Forms!frmbenefitsstatuschangemaintain.ManageStatusChange("pcAdd")
0
 
dminx13Author Commented:
Nope, that didn't work. The single quote did nothing. The double quotes gave me Compile Error: Expected: end of statement.
0
 
dminx13Author Commented:
Plus this one works. Albeit differently when I follow the code.
Private Sub treeJCC_MouseDown(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Long, ByVal Y As Long)
    '  Open a short cut menu that can be used to add a new JCC
    
    If Button = acRightButton Then
        Call DeleteMenu("JCCAdd")
        Call CreateJCCMenu
    End If
End Sub
Private Sub CreateJCCMenu()
    '  Procedure isused to create the JCC Add New Menu
    Dim X As CommandBar
    Dim Y As CommandBarButton
    
    
    Set X = CommandBars.Add("JCCAdd", msoBarPopup)
    
    Set Y = X.Controls.Add(msoControlButton)
    
    With Y
        .Caption = "Add New JCC"
        .OnAction = "=AddNewJCC(" + "'" + "JCC" + "'" + ")"
    End With
    
    X.ShowPopup
    
End Sub

Open in new window

'***********************************************************************************
'
'  MENU FUNCTION FOUND AS A SHORTCUT ON THE HEALTH TEST FORM ONLY
'
'****************************************************************************
Public Function AddNewJCC(JCC As String)
    '  Function is used to add a new JCC
    
    '  Pass value back to the Job Class Code Form
    Forms!frmDBAjobClassCode.AddJobClassCode (JCC)
    
End Function

Open in new window

    '  Procedure is used to add a job class code
    
    
    '  Open the JCC add new form
    DoCmd.Openform "frmDBAJobClassCodeAddNew", , , , , acDialog
    
    '  Did the user add a new Job Class Code
    If varPassData <> "NoJCC" Then
        '  requery the recordset
        rsJCC.Requery
        '  Delete all records in the tree and add them again
        Call DeleteTreenodes
        Call LoadTree(rsJCC)
        '  highlight the node and load the data for the new JCC
        Call HighlightNode(CStr(varPassData))
        '  Display the new jcc record
        Call EnableControls(True)
        Call DisplayJCCRecords(CStr(varPassData))
        '  add the new JCC to G2
        Me.stBar.Panels(1).Text = "Adding to G2 Database . . . "
        Call G2UpdateJCC(CStr(varPassData))
    End If
    
    
End Function

Open in new window


I try doing that with the Status Change and it tells me the form doesn't exist when I get to the
Forms!frmBenefitsStatusChangeAddNew.AddNewStatusChange (pcAdd) line. So that didn't work.....
'***********************************************************************************
'
'  MENU FUNCTION FOUND AS A SHORTCUT ON THE STATUS CHANGE FORM ONLY
'
'****************************************************************************
Public Function AddNewStatusChange(pcAdd As String)
    '  Function is used to add a new JCC
    
    '  Pass value back to the Job Class Code Form
    Forms!frmBenefitsStatusChangeAddNew.AddNewStatusChange (pcAdd)
    
End Function

Open in new window

'***********************************************************************************
'
'  MENU FUNCTION FOUND AS A SHORTCUT ON THE STATUS CHANGE FORM ONLY
'
'****************************************************************************
Public Function AddNewStatusChange(pcAdd As String)
    '  Function is used to add a new Status Change
    
    '  Pass value back to the Status Change Form
    Forms!frmBenefitsStatusChangeAddNew.AddNewStatusChange (pcAdd)
    
End Function

Open in new window

0
Fill in the form and get your FREE NFR key NOW!

Veeam is happy to provide a FREE NFR server license to certified engineers, trainers, and bloggers.  It allows for the non‑production use of Veeam Agent for Microsoft Windows. This license is valid for five workstations and two servers.

 
Scott McDaniel (Microsoft Access MVP - EE MVE )Infotrakker SoftwareCommented:
the form doesn't exist
Are you sure that "frmbenefitsstatuschangemaintain" is open, and is being used as a standard Form (i.e. not a Subform)? In order for your code to run, that form would need to be open as a Standard form.
0
 
dminx13Author Commented:
Yes, and as far I know it is not a subform.
0
 
dminx13Author Commented:
I was coding it incorrectly!!! frmbenefitsstatuschangemaintain was supposed to be the form not frmBenefitsStatusChangeAddNew.
0

Featured Post

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

  • 4
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now