Which Event to give field a value

  • Thread starter gmazza via AccessMonster.com
  • Start date
G

gmazza via AccessMonster.com

Hey there,
I need to my 2 fields, ModifierID and ModifierDate to be updated when a
record gets inserted into the table, however they are dynamic, no user entry
for these obviously. They both call for their own separate routines.
I tried putting them into the Before Update Event and it works for 1 record
but not for the next record that has updating, it errors on Run-time error:
Update or CancelUpdate without AddNew or Edit.
I have been doing some reading that says the Before Update Event is not a
good place to assign values so where can I assign these values?
Thanks in advance!
 
A

Arvin Meyer MVP

Try using the AfterUpdate event. I know that it doesn't seem logical not to
use the Before Update event, but that event is used mostly for validating
data (or lack thereof) on a form.
 
G

gmazza via AccessMonster.com

Now I get this error when I put it there:
You cancelled the previous operation.
However the error is in my combo box after update with this code in it:
Dim rs As Object
Set rs = Me.Recordset.Clone
rs.FindFirst "[MovieID] = " & str(Nz(Me![cboSelectMovie], 0))
If Not rs.EOF Then Me.Bookmark = rs.Bookmark

The error was on the last line.
Try using the AfterUpdate event. I know that it doesn't seem logical not to
use the Before Update event, but that event is used mostly for validating
data (or lack thereof) on a form.
Hey there,
I need to my 2 fields, ModifierID and ModifierDate to be updated when a
[quoted text clipped - 9 lines]
good place to assign values so where can I assign these values?
Thanks in advance!
 
A

Arvin Meyer MVP

Let us see the entire code listing, not just a snippet from inside.
--
Arvin Meyer, MCP, MVP
http://www.datastrat.com
http://www.mvps.org/access
http://www.accessmvp.com


gmazza via AccessMonster.com said:
Now I get this error when I put it there:
You cancelled the previous operation.
However the error is in my combo box after update with this code in it:
Dim rs As Object
Set rs = Me.Recordset.Clone
rs.FindFirst "[MovieID] = " & str(Nz(Me![cboSelectMovie], 0))
If Not rs.EOF Then Me.Bookmark = rs.Bookmark

The error was on the last line.
Try using the AfterUpdate event. I know that it doesn't seem logical not
to
use the Before Update event, but that event is used mostly for validating
data (or lack thereof) on a form.
Hey there,
I need to my 2 fields, ModifierID and ModifierDate to be updated when a
[quoted text clipped - 9 lines]
good place to assign values so where can I assign these values?
Thanks in advance!
 
G

gmazza via AccessMonster.com

This is all the code I have for the form and going back to my original error,
I left the modifier assigning in the BeforeUpdate, as that was where I was
getting the original error.
Actually, the AfterUpdate code has to be the problem because when I take it
out, change a record, and move to the next record NOT using the combo box but
by using the record selector buttons at the bottom of the screen, I can
change multiple records without getting any error. Weird??


Private Sub cboSelectMovie_AfterUpdate()
Dim rs As Object
Set rs = Me.Recordset.Clone
rs.FindFirst "[MovieID] = " & str(Nz(Me![cboSelectMovie], 0))
If Not rs.EOF Then Me.Bookmark = rs.Bookmark
End Sub

Private Sub Form_AfterUpdate()
cboSelectMovie.Requery
End Sub

Private Sub Form_BeforeUpdate(Cancel As Integer)

ModifierID = ap_GetUserName
ModifierDate = TimeAndDate

End Sub
Let us see the entire code listing, not just a snippet from inside.
Now I get this error when I put it there:
You cancelled the previous operation.
[quoted text clipped - 15 lines]
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top