Deleting a blank record in a form

G

Guest

I need help with error handling. In a form that contains navigation buttons,
if a user were to create a new record and starts to type some data, but
decided to change their mind, Access will give an error message if they try
to back out by closing the form or by trying to move to a different record.
It makes sense because the field(s) for the record are required, so a blank
entry is not acceptable.

What I'd like to do is create a user friendly message, asking the user if
they'd like to delete the blank entry, so if that's what they want, they
don't get a series of errors. Here's what I got so far:

Select Case DataErr
Case 3314
MsgBox "The new record can't be blank. Do you want to delete the
blank _ entry?", vbYesNo, "Blank Record"
If vbYes Then
error_BlankEntry
Else
Exit Sub
End If
Case Else

MsgBox "Error " & Err.Number & " - " & Err.Description, vbCritical

End Select
End Sub

--------
Private Sub error_BlankEntry()
DoCmd.DoMenuItem acFormBar, acEditMenu, 8, , acMenuVer70
DoCmd.DoMenuItem acFormBar, acEditMenu, 6, , acMenuVer70


End Sub


I get a runtime error 2115 message: The macro or function set to
BeforeUpdate or ValidationRule property for th is field is preventing your
form from saving the data in the field. The first line of the
error_blankentry sub is highlighted. I thought that line just selects the
current record, so it doesn't make sense to me.

Also, I don't seem to find any beforeupdate or validationrule properties
that are causing the problem.

I can't just add a delete button to the form either because it won't work if
the entry is blank.

Please advise!
AA
 
G

Guest

I've been using this method:

Private Sub Form_BeforeUpdate(Cancel As Integer)
Dim ctl As Control

On Error GoTo Err_BeforeUpdate


If Me.Dirty Then

If MsgBox("Data Has been modified! Do you want to save?", vbYesNo +
vbQuestion, _
"Save Record") = vbNo Then
Me.Undo
End If
End If

Exit_BeforeUpdate:
Exit Sub

Err_BeforeUpdate:
MsgBox Err.Number & " " & Err.Description
Resume Exit_BeforeUpdate
End Sub

Maybe it will work with yours?

CW
 

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

Similar Threads


Top