Run-time error '2115'

G

Guest

I posted the below message yesterday and got the attached response and made
the changes to the before update event in the 'form':
If Me.Dirty Then
Me.Dirty = False
End If
DoCmd.Close acForm, Me.Name
End Sub

It gave me an error. Here is what is says: "Run-time error '2115'; The
macro or function set to the Before Update or validation rule property for
this field is preventing microsoft access from saving the data in the field."

I have no idea what this means, does anyone else? Any other suggestions? I
am very new to access so please explain it to me like a two year old. Thanks
for your help. - Lori

---------------------------
ORIGINAL MESSAGE

For some reason the the default messages when closing a record that comes up
for required fields when null, is not working anymore. I was told that
sometimes default functions in access like this stop working sometimes. So I
added the code below. Now when you enter a duplicate in the required field,
no duplicates allowed. It still does not allow for duplicates, but the
default message does not pop up, just like the required field message. It
just does not save the record.

Can someone tell me what I would need to add to the below to include no
duplicates or should I add it under a different event other than "on click"
on the command button to close the record.

If IsNull(Me![ContactCompanyID]) Then
If MsgBox("'File Number' must contain a value." & Chr(13) & Chr(10) & _
"Press 'OK' to return and enter a value." & Chr(13) & Chr(10) & _
"Press 'Cancel' to abort the record.", _
vbOKCancel, "File Number is a required field") = vbCancel Then
DoCmd.Close
Else
Me![ContactCompanyID].SetFocus
End If
Else
If IsNull(Me![UpdatedOn]) Then
If MsgBox("'Updated On' must contain a value." & Chr(13) & Chr(10) & _
"Press 'OK' to return and enter a value." & Chr(13) & Chr(10) & _
"Press 'Cancel' to abort the record.", _
vbOKCancel, "Updated On is a required field") = vbCancel Then
DoCmd.Close
Else
Me![UpdatedOn].SetFocus
End If
Else
If IsNull(Me![UpdatedBy]) Then
If MsgBox("'Updated By' must contain a value." & Chr(13) & Chr(10) & _
"Press 'OK' to return and enter a value." & Chr(13) & Chr(10) & _
"Press 'Cancel' to abort the record.", _
vbOKCancel, "Updated By is a required field") = vbCancel Then
DoCmd.Close
Else
Me![UpdatedBy].SetFocus
End If
Else
DoCmd.Close
End If
End If
End If
--
Thank, Lori

---------------------------------
ORIGINAL RESPONSE - SOLUTION

Allen Browne 5/15/2006 7:14 AM PST

Lori, you are in a very long line of users who continue to get hurt by this
bug in Access. As you found, it just silently discards you data with no
warning when you execute the Close action or method. More info in this
article:
Losing data when you close a form
at:
http://allenbrowne.com/bug-01.html

Assuming this is a bound form, you should place your validation checks in
the BeforeUpdate event of the *form*.

Then in the Click event of your of your command button, explicitly save
before you Close. This triggers a trappable error if the record cannot be
saved, so the Close never executes, and so you have worked around the bug.

Private Sub cmdClose_Click()
If Me.Dirty Then
Me.Dirty = False
End If
DoCmd.Close acForm, Me.Name
End Sub
 
A

Allen Browne

In plain English, the message is saying, "You can't close the form now,
because the record cannot be saved at the moment."

To give the user choices such as:
- going back and finishing the entry, or
- undoing the record and closing the form,
you need to add error handling to the code.

If error handling is new, see:
http://allenbrowne.com/ser-23a.html
The article explains how to create a table and log the errors. You don't
have to do that, but it also illustrates how to use error handling in
general.

--
Allen Browne - Microsoft MVP. Perth, Western Australia.

Reply to group, rather than allenbrowne at mvps dot org.

Lori said:
I posted the below message yesterday and got the attached response and made
the changes to the before update event in the 'form':
If Me.Dirty Then
Me.Dirty = False
End If
DoCmd.Close acForm, Me.Name
End Sub

It gave me an error. Here is what is says: "Run-time error '2115'; The
macro or function set to the Before Update or validation rule property for
this field is preventing microsoft access from saving the data in the
field."

I have no idea what this means, does anyone else? Any other suggestions?
I
am very new to access so please explain it to me like a two year old.
Thanks
for your help. - Lori

---------------------------
ORIGINAL MESSAGE

For some reason the the default messages when closing a record that comes
up
for required fields when null, is not working anymore. I was told that
sometimes default functions in access like this stop working sometimes. So
I
added the code below. Now when you enter a duplicate in the required
field,
no duplicates allowed. It still does not allow for duplicates, but the
default message does not pop up, just like the required field message. It
just does not save the record.

Can someone tell me what I would need to add to the below to include no
duplicates or should I add it under a different event other than "on
click"
on the command button to close the record.

If IsNull(Me![ContactCompanyID]) Then
If MsgBox("'File Number' must contain a value." & Chr(13) & Chr(10) & _
"Press 'OK' to return and enter a value." & Chr(13) & Chr(10) & _
"Press 'Cancel' to abort the record.", _
vbOKCancel, "File Number is a required field") = vbCancel Then
DoCmd.Close
Else
Me![ContactCompanyID].SetFocus
End If
Else
If IsNull(Me![UpdatedOn]) Then
If MsgBox("'Updated On' must contain a value." & Chr(13) & Chr(10) & _
"Press 'OK' to return and enter a value." & Chr(13) & Chr(10) & _
"Press 'Cancel' to abort the record.", _
vbOKCancel, "Updated On is a required field") = vbCancel Then
DoCmd.Close
Else
Me![UpdatedOn].SetFocus
End If
Else
If IsNull(Me![UpdatedBy]) Then
If MsgBox("'Updated By' must contain a value." & Chr(13) & Chr(10) & _
"Press 'OK' to return and enter a value." & Chr(13) & Chr(10) & _
"Press 'Cancel' to abort the record.", _
vbOKCancel, "Updated By is a required field") = vbCancel Then
DoCmd.Close
Else
Me![UpdatedBy].SetFocus
End If
Else
DoCmd.Close
End If
End If
End If
--
Thank, Lori

---------------------------------
ORIGINAL RESPONSE - SOLUTION

Allen Browne 5/15/2006 7:14 AM PST

Lori, you are in a very long line of users who continue to get hurt by
this
bug in Access. As you found, it just silently discards you data with no
warning when you execute the Close action or method. More info in this
article:
Losing data when you close a form
at:
http://allenbrowne.com/bug-01.html

Assuming this is a bound form, you should place your validation checks in
the BeforeUpdate event of the *form*.

Then in the Click event of your of your command button, explicitly save
before you Close. This triggers a trappable error if the record cannot be
saved, so the Close never executes, and so you have worked around the bug.

Private Sub cmdClose_Click()
If Me.Dirty Then
Me.Dirty = False
End If
DoCmd.Close acForm, Me.Name
End Sub
 

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