BeforeUpdate and Me.Dirty

G

Guest

If have this code in the BeforeUpdate event:
If Me.Dirty Then
If IsNull(text_switch) Then
MsgBox ("My Message!!!!")
Me.Dirty = False
stDocName = "a_hefte_verbindung"
DoCmd.OpenForm stDocName, , , stLinkCriteria
End If
End If

Access always gives a runtime error with the Me.Dirty part:
errorr 2115

Why isn't me.dirty not working???
 
G

Guest

I assume that the error happen in this line

Me.Dirty = False

You are trying to save the records, just before the records are saved, so
there is not need for this line
 
S

Sandra Daigle

If you want to cancel an update to the form you need to set Cancel = True
instead of trying to modify the dirty property.

Also, the first statement is redundant in the BeforeUpdate event. The event
is only going to fire when the record is dirty. Here is how you can modify
your code:

If IsNull(text_switch) Then
MsgBox ("My Message!!!!")
Cancel=true
stDocName = "a_hefte_verbindung"
DoCmd.OpenForm stDocName, , , stLinkCriteria
End If
 

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