jesselavaca
asked on
Access 2000: Updating SubForm Charts...need new event?
Experts,
This has been bugging me -
I made a form that displays all the employees, and a subform displays a chart that graphs where each employee's expenses are categorized. To get the chart to update I had to set the Chart Query/DataSource to:
--------
SELECT Category, Sum([TransactionsQuery].Co st) AS SumOfCost, [TranactionsQuery].Employe eID
FROM [TransactionsQuery]
WHERE ((([TransactionsQuery].Emp loyeeID)=[ Forms]![fr mEmployeeS pendCharts ].[Employe eID]))
GROUP BY [TransactionsQuery].Catego ry, [TransactionsQuery].Employ eeID;
--------
The Where Clause was my favorite part...
The next part to figure out was how to get the chart to update as I cycle through employees - so I searched on here and found that I could use the On Current Event for the Form, and it worked. (love this site)
----
Private Sub Form_Current()
Forms(frmEmployeeSpendChar ts).Refres h
End Sub
-------
But...
I put a button on the main form to open the frmEmployeeSpendCharts, and when the form updates I can cycle through the employees, but the chart does not update anymore. Is this because the form opens Modal or something? Is there another event I can use to make the chart update again again? When I open the form just by double clicking on it in the Access window, it works fine....I think the problem lies in how the main form handles it:
-----------------------
Private Sub cmdOpenEmployeeSpendCharts _Click()
On Error GoTo Err_cmdOpenEmployeeSpendCh arts_Click
Dim stDocName As String
Dim stLinkCriteria As String
stDocName = "frmEmployeeSpendCharts"
DoCmd.OpenForm stDocName, , , stLinkCriteria
Exit_cmdOpenEmployeeSpendC harts_Clic k:
Exit Sub
Err_cmdOpenEmployeeSpendCh arts_Click :
MsgBox Err.Description
Resume Exit_cmdOpenEmployeeSpendC harts_Clic k
End Sub
-----------------
-Jess
PS - I'm sure you'll need more info from me, so just ask and I'll respond...
This has been bugging me -
I made a form that displays all the employees, and a subform displays a chart that graphs where each employee's expenses are categorized. To get the chart to update I had to set the Chart Query/DataSource to:
--------
SELECT Category, Sum([TransactionsQuery].Co
FROM [TransactionsQuery]
WHERE ((([TransactionsQuery].Emp
GROUP BY [TransactionsQuery].Catego
--------
The Where Clause was my favorite part...
The next part to figure out was how to get the chart to update as I cycle through employees - so I searched on here and found that I could use the On Current Event for the Form, and it worked. (love this site)
----
Private Sub Form_Current()
Forms(frmEmployeeSpendChar
End Sub
-------
But...
I put a button on the main form to open the frmEmployeeSpendCharts, and when the form updates I can cycle through the employees, but the chart does not update anymore. Is this because the form opens Modal or something? Is there another event I can use to make the chart update again again? When I open the form just by double clicking on it in the Access window, it works fine....I think the problem lies in how the main form handles it:
-----------------------
Private Sub cmdOpenEmployeeSpendCharts
On Error GoTo Err_cmdOpenEmployeeSpendCh
Dim stDocName As String
Dim stLinkCriteria As String
stDocName = "frmEmployeeSpendCharts"
DoCmd.OpenForm stDocName, , , stLinkCriteria
Exit_cmdOpenEmployeeSpendC
Exit Sub
Err_cmdOpenEmployeeSpendCh
MsgBox Err.Description
Resume Exit_cmdOpenEmployeeSpendC
End Sub
-----------------
-Jess
PS - I'm sure you'll need more info from me, so just ask and I'll respond...
If you remove the stLinkCriteria part, does the chart update when you open it via the button?
ASKER
I changed it to just:
DoCmd.OpenForm stDocName
and the chart didn't update...
-Jess
DoCmd.OpenForm stDocName
and the chart didn't update...
-Jess
Oh hold on a second, let me get this straight - you've got a main form based on the employees table. In this form is a subform containing your chart. Your code to refresh the subform is in the OnCurrent event of the *main* form, is that right?
ASKER
That's pretty much correct...
-Main Form: has buttons to link to all the other forms
-EmployeeSpend Form: shows the employees
-sfrmEmployeeSpend: has the chart that updates for each employee
-Jess
-Main Form: has buttons to link to all the other forms
-EmployeeSpend Form: shows the employees
-sfrmEmployeeSpend: has the chart that updates for each employee
-Jess
OK, to update the subform, try changing your refresh line to this:
Me!MySubformControl.Form.R efresh
MySubformControl is the name of the *control* that the chart subform is held in - design the main form, click on the subform, click View-Properties and check the Name property on the Other page. This might (but probably won't) be the same as the name of the subform that it contains.
Me!MySubformControl.Form.R
MySubformControl is the name of the *control* that the chart subform is held in - design the main form, click on the subform, click View-Properties and check the Name property on the Other page. This might (but probably won't) be the same as the name of the subform that it contains.
ASKER
Thanks for the specific directions...but that's still not it yet.
Me![qryID-Name-Cost-KSB1Ch arts subform].Form.Refresh
is under the
"Private Sub Form_Current()" piece of the EmployeeSpendForm
Another thought: would it matter if I declared this as Public?
-Jess
Me![qryID-Name-Cost-KSB1Ch
is under the
"Private Sub Form_Current()" piece of the EmployeeSpendForm
Another thought: would it matter if I declared this as Public?
-Jess
No, it shouldn't make a difference - the Current event of the main form should be fired whenever you move to a new record there. Is the chart still not refreshing? Try changing the Refresh to Requery, and see if that makes a difference.
Also, is the subform linked to the main form by any child/master fields?
Also, is the subform linked to the main form by any child/master fields?
ASKER
Requery didn't do it...
and yes, there is a child/master link - EmployeeID.
-Jess
and yes, there is a child/master link - EmployeeID.
-Jess
I noticed this on your query:
[Forms]![frmEmployeeSpendC harts].[Em ployeeID]
Try changing it to:
[Forms]![EmployeeSpendForm ]![qryID-N ame-Cost-K SB1Charts subform].Form![EmployeeID]
The reason is that, if frmEmployeeSpendCharts is open as a subform, you can't reference it directly - it isn't part of the Forms collection, so you need to refer to it indirectly via its parent/subform control.
[Forms]![frmEmployeeSpendC
Try changing it to:
[Forms]![EmployeeSpendForm
The reason is that, if frmEmployeeSpendCharts is open as a subform, you can't reference it directly - it isn't part of the Forms collection, so you need to refer to it indirectly via its parent/subform control.
ASKER
Things got more weird.
So I realized the chart did not have a child/master link...another subform displaying a datasheet of the values did. I added it, and now when I load the form from the menu it works and updates - but only once. Odd.
However, when I changed the query, it gave me a crazy error..."Object yadayada error", I CTRL+BREAK'ed it, Debugged, and it was the Requery statement, so I changed it to Refresh and the problem went away.
So now the question is, why does it only update itself once?
-Jess
PS - I leave for the day in another 10 minutes, won't be back until Friday morning...
So I realized the chart did not have a child/master link...another subform displaying a datasheet of the values did. I added it, and now when I load the form from the menu it works and updates - but only once. Odd.
However, when I changed the query, it gave me a crazy error..."Object yadayada error", I CTRL+BREAK'ed it, Debugged, and it was the Requery statement, so I changed it to Refresh and the problem went away.
So now the question is, why does it only update itself once?
-Jess
PS - I leave for the day in another 10 minutes, won't be back until Friday morning...
OK, post back when you get back and we'll work through it from there.
ASKER
and I'm back!
So where I left off...the main form links to the charts, it loads the data and charts the first employee's spend, then I advance one record and the chart updates again...but then it no longer updates no matter which direction I go.
Jess
So where I left off...the main form links to the charts, it loads the data and charts the first employee's spend, then I advance one record and the chart updates again...but then it no longer updates no matter which direction I go.
Jess
I'm not sure why it only updates once - could you try modifying the chart's query so that it gets its criteria directly from the main form (in other words, include a criteria in its query on the EmployeeID field, something like = Forms!MyMainForm!txtEmploy eeID), and then remove the master/child links. Does that make a difference?
Before you do that though, just a thought - try requerying the chart directly, something like:
Me![qryID-Name-Cost-KSB1Ch arts subform].Form!MyChartContr ol.Requery
Before you do that though, just a thought - try requerying the chart directly, something like:
Me![qryID-Name-Cost-KSB1Ch
ASKER
So I made the latter change first - the Requery...it didn't change anything so far as I could tell...
Then I removed the master link and now the updating isn't happening at all (not even that first one I was getting).
Weird,
Jess
Then I removed the master link and now the updating isn't happening at all (not even that first one I was getting).
Weird,
Jess
Did you include a requery when the master/child link was removed? You must include the criteria in the query as well for it to (hopefully) work.
ASKER
I did - the Chart SQL is now:
-----------
SELECT [qryID-Name-Cost-KSB1Chart s].Specifi cName, Sum([qryID-Name-Cost-KSB1C harts].Cos t) AS SumOfCost, [qryID-Name-Cost-KSB1Chart s].Employe eID
FROM [qryID-Name-Cost-KSB1Chart s]
WHERE ((([qryID-Name-Cost-KSB1Ch arts].Empl oyeeID)=[F orms]![frm EmployeeSp endCharts] .[Employee ID]))
GROUP BY [qryID-Name-Cost-KSB1Chart s].Specifi cName, [qryID-Name-Cost-KSB1Chart s].Employe eID;
------------
and the Event OnCurrent on the main form is:
Me![qryID-Name-Cost-KSB1Ch arts subform].Form.Requery
More thoughts?
Jess
-----------
SELECT [qryID-Name-Cost-KSB1Chart
FROM [qryID-Name-Cost-KSB1Chart
WHERE ((([qryID-Name-Cost-KSB1Ch
GROUP BY [qryID-Name-Cost-KSB1Chart
------------
and the Event OnCurrent on the main form is:
Me![qryID-Name-Cost-KSB1Ch
More thoughts?
Jess
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Well, I'll be damned....
It worked.
Congrats on another obscure question answered...and it's a shame they cap these at 500 points.
-Jess
It worked.
Congrats on another obscure question answered...and it's a shame they cap these at 500 points.
-Jess
No probs, glad we got there in the end :)