[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Right Click on form not working

Posted on 2013-12-10
6
Medium Priority
?
467 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 2
6 Comments
 
LVL 85
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
What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

 
LVL 85

Accepted Solution

by:
Scott McDaniel (Microsoft Access MVP - EE MVE ) earned 2000 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If you need a simple but flexible process for maintaining an audit trail of who created, edited, or deleted data from a table, or multiple tables, and you can do all of your work from within a form, this simple Audit Log will work for you.
This article shows how to get a list of available printers for display in a drop-down list, and then to use the selected printer to print an Access report or a Word document filled with Access data, using different syntax as needed for working with …
In Microsoft Access, learn how to use Dlookup and other domain aggregate functions and one method of specifying a string value within a string. Specify the first argument, which is the expression to be returned: Specify the second argument, which …
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…

656 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