Access 2003 Going to previous record in Before Update Event

G

Guest

Please help.

If a user selects to enter a new form, but does not want to enter the form
at that time and returns back to the previous completed form using the record
navigation buttons, I do not want the uncompleted form as a new record. I am
trying to use VBA to go back to the previous record on the form when the new
form is not completed.

We are currently converting from Access 97 to Access 2003. I used the
following code in Access 97 to accomplish my task:

Private Sub Form_BeforeUpdate(Cancel As Integer)
'if this data sheet has no code, code description, record title, location or
record date do not update
If IsNull([Form_Record Summary].code) _
And IsNull([Form_Record Summary].code_desc) _
And IsNull([Form_Record Summary].record_title) _
And IsNull([Form_Record Summary].location) _
And IsNull([Form_Record Summary].record_date) _
Then
MsgBox "This record will not be updated."
DoCmd.GoToControl "department"
SendKeys "{ESC}", True
DoCmd.GoToRecord , , acPrevious
Else
Exit Sub
End If

End Sub

This does not work in Access 2003; I get the run time error '2105': you
can't go to the specified record.

I've tried to replace DoCmd.GoToRecord , , acPrevious with SendKeys "{UP}"
as follows:

Private Sub Form_BeforeUpdate(Cancel As Integer)
'if this data sheet has no code, code description, record title, location or
record date do not update
If IsNull([Form_Record Summary].code) _
And IsNull([Form_Record Summary].code_desc) _
And IsNull([Form_Record Summary].record_title) _
And IsNull([Form_Record Summary].location) _
And IsNull([Form_Record Summary].record_date) _
Then
DoCmd.CancelEvent
DoCmd.GoToControl "department"
SendKeys "{ESC}", True
SendKeys "{PGUP}", True
MsgBox "This record will not be updated."
Else
Exit Sub
End If

End Sub

I recieve the MsgBox but the VBA code does not move off of the unwanted
record when the navigation button is selected for the next record.

Does anyone have other suggestions?
 
G

Guest

Nevermind. After reading some threads about BeforeUpdate event, I decided to
use AfterInsert Event and modified the code a little.

It seems to be working fine now.
 

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