Solved

Right Click on form not working

Posted on 2013-12-10
6
417 Views
Last Modified: 2013-12-11
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
Comment
Question by:dminx13
  • 4
  • 2
6 Comments
 
LVL 84
ID: 39710924
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
 

Author Comment

by:dminx13
ID: 39711932
Nope, that didn't work. The single quote did nothing. The double quotes gave me Compile Error: Expected: end of statement.
0
 

Author Comment

by:dminx13
ID: 39712010
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
Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

 
LVL 84

Accepted Solution

by:
Scott McDaniel (Microsoft Access MVP - EE MVE ) earned 500 total points
ID: 39712282
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
 

Author Comment

by:dminx13
ID: 39712872
Yes, and as far I know it is not a subform.
0
 

Author Closing Comment

by:dminx13
ID: 39712920
I was coding it incorrectly!!! frmbenefitsstatuschangemaintain was supposed to be the form not frmBenefitsStatusChangeAddNew.
0

Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

In the previous article, Using a Critera Form to Filter Records (http://www.experts-exchange.com/A_6069.html), the form was basically a data container storing user input, which queries and other database objects could read. The form had to remain op…
Regardless of which version on MS Access you are using, one of the harder data-entry forms to create is one where most data from previous entries needs to be appended to new records, especially when there are numerous fields and records involved.  W…
Basics of query design. Shows you how to construct a simple query by adding tables, perform joins, defining output columns, perform sorting, and apply criteria.
In Microsoft Access, learn different ways of passing a string value within a string argument. Also learn what a “Type Mis-match” error is about.

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now