Calling Macro within Event Procedure

marnieg

Registered User.
Local time
Today, 06:19
Joined
Jul 21, 2009
Messages
70
I have a form that on the "AfterUpdate" it calls an Event Procedure that does three things.

1. Runs a Macro that does a "Set Value" to another field on the form
2. Executes a SQL statement that performs a Sum on the field that just got updated in the macro.
3. Executes a SQL statement that performs an Update to another table with the sum that was computed.

My problem is that the value the Macro is setting is not being included in the Sum/Update statements. Here is my code for reference.

Private Sub UpdateTotal

DoCmd.RunMacro "Update Total"
' this sets the value of bau_total on the form

intTotal = DSum("bau_total", "BallotUsage", "bau_loc = '" & Me![bau_loc] & "' and bau_type = '" & Me![bau_type] & "' and bau_pre = '" & Me![bau_pre] & "'")

If intTotal > 0 Then
CurrentDb.Execute "Update [Ballot Percent Alerts] set bpa_total = " & intTotal & " where bpa_loc = '" & Me![bau_loc] & "' and bpa_type = '" & Me![bau_type] & "' and bpa_pre = '" & Me![bau_pre] & "'"
End If

End Sub

How can I get the macro to commit the value to the database so that it will be included in the Dsum OR is there another way to accomplish this.:confused:
 
This should save the current record:

DoCmd.RunCommand acCmdSaveRecord
 
Thanks for the quick reply and the solution. I can always count on this forum to help me out with my questions. I hope that I can be of help to others soon.
 
No problem. Personally, I would dump the macro and just set the value in code:

Me.ControlName = Whatever
 
Thanks for the input. Yes, I agree about getting rid of the macro.
 

Users who are viewing this thread

Back
Top Bottom