RECORDS DELETED MYSTERIOUSLY

G

Guest

I'm Using Access 2000 on a form to add a new record to a table. Please help
me figure out why records are being deleted with the following code:

Private Sub Form_BeforeUpdate(Cancel As Integer)
Dim strMessage As String
Dim intOptions As Integer
Dim bytChoice As Byte

If IsNull(Status) Then
strMessage = "You didn't indicate what you are waiting for. Do you
want to do this now?"
intOptions = vbQuestion + vbYesNo
bytChoice = MsgBox(strMessage, intOptions)

If bytChoice = vbYes Then
Cancel = True
Status.SetFocus
End If

End If
End Sub

Records get deleted when I say yes. I think if I say no, the
"Form_beforeupdate" procedure ends and I don't loose records, but I'm not
positive. Allow deletions on this form is set to "no".

Thank you.
Sammie
 
L

lbrinkman

Why are you using the "BeforeUpdate" event to save data at all?
If the form is "bound", simply leaving that record saves it.

If your purpose is make sure that "Satus" has data in it before a record can
be save, there are many better ways, such as using the form's "Unload" event
or "Close" event.

Private Sub Form_Unload(Cancel As Integer)
Dim strMessage As String
Dim intOptions As Integer
Dim intChoice As Integer
Dim strTitle as String
If IsNull(Me![Status)] or Me![Status] = "" Then
strMessage = "You didn't indicate what you are waiting for. Do you
want to do this now?"
intOptions = vbQuestion + vbYesNo
strTitle = "Status Not Filled In"
intChoice = MsgBox(strMessage, intOptions, strTitle)
'
If intChoice = vbYes Then
Cancel = True
Me![Status].SetFocus
Else
'do nothing
End If
End If
End Sub

---Phil Szlyk
 
G

Guest

The "Cancel = True" statement within the BeforeUpdate event causes Access to
abort the record update sequence of events. That's why no records are
created when you respond "Yes" to the MsgBox

Tom
 

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

Pesky button issue 2
Can't find project or library 2
command button validation 2
SetWarning False.....? 10
Case vbNo 5
Checking calculations and showing message 2
Object Required Error 1
Default Value 4

Top