dminx13
asked on
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 frmBenefitsStatusChangeAdd New but it isn't. It is just bypassing everything altogether. I have other forms that work properly so I'm confused. Any thoughts?
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 frmBenefitsStatusChangeAdd
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
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
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
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
ASKER
Nope, that didn't work. The single quote did nothing. The double quotes gave me Compile Error: Expected: end of statement.
ASKER
Plus this one works. Albeit differently when I follow the code.
I try doing that with the Status Change and it tells me the form doesn't exist when I get to the
Forms!frmBenefitsStatusCha ngeAddNew. AddNewStat usChange (pcAdd) line. So that didn't work.....
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
'***********************************************************************************
'
' 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
' 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
I try doing that with the Status Change and it tells me the form doesn't exist when I get to the
Forms!frmBenefitsStatusCha
'***********************************************************************************
'
' 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
'***********************************************************************************
'
' 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
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Yes, and as far I know it is not a subform.
ASKER
I was coding it incorrectly!!! frmbenefitsstatuschangemai ntain was supposed to be the form not frmBenefitsStatusChangeAdd New.
Forms!frmbenefitsstatuscha
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!frmbenefitsstatuscha
or
Forms!frmbenefitsstatuscha