Error Saving Record Before Printing

  • Thread starter Thread starter Bonnie
  • Start date Start date
B

Bonnie

Hi there! Using A02 on XP. Have a data entry form that
assigns points to various selections and has a field
[Total] calculating as you go. When finished, I need to
copy the [Total] sum to [Points] and then view the report.
(I need the final result to be recorded in a linked table
for future reference.) When I click the button, I can see
the field update but then I get Runtime Error 2501 - The
RunCommand Action was cancelled. If I don't save the
record, my report prints without the updates/edits. Here
is my event code:

Private Sub Preview_Click()

Me.Points = Me.Total
DoCmd.RunCommand acCmdSaveRecord

On Error GoTo Err_Preview_Click
Dim stDocName As String

stDocName = "rPoints"
DoCmd.OpenReport stDocName, acPreview, , "[PointsNum]
=" & [PointsNum]
DoCmd.RunCommand acCmdZoom100

Exit_Preview_Click:
Exit Sub

Err_Preview_Click:
MsgBox Err.Description
Resume Exit_Preview_Click

End Sub

I hope it's something simple but cannot figure out why I
cannot put a final save on the data before the report
opens up. Thanks in advance for any and all help or
advice. I love you guys!
 
Bonnie,

At first glance, I can't see anything wrong with your code. One possible
reason is that the query being the form's recordset is not updateable. Have
you checked that this is not the case? One way to check is to manually enter
a value in [Points] and then try to move to another record so as to force
Access to save the record, and see if the value does get saved, and if you
get an error message or not... or you could open the query in datasheet
view, and see if it allows you to make changes in the field and save them.
If it turns out the query is not updateable, a working workaround is to make
the Points control on the form unbound, or even drop it altogether, since
you already have the number in Total, and use a recordset operation in code
to update the table with Points.

HTH,
Nikos
 
Back
Top