Go Back   Access World Forums > Microsoft Access Discussion > Forms

 
Reply
 
Thread Tools Rate Thread Display Modes
Old 01-30-2008, 06:47 AM   #1
robben
Registered User
 
Join Date: Jan 2008
Posts: 52
Thanks: 0
Thanked 0 Times in 0 Posts
robben is on a distinguished road
BeforeUpdate Error 2115

Hi,

I have a form and when the user clicks on the save record command button
it calls the Form_BeforeUpdate event function. Also, the Form_BeforeUpdate
shall be called when the user presses the close button (top X button).

The function checks the values entered into textboxes and comboboxes etc
are valid. If they are deemed to be valid the data is written to to a number
of tables using SQL statements INSERT/UPDATE depending on whether it is
a new record or he/she is updating a previous record. However, as it reaches
the first Insert statement the system gives me the following error message:

"Run-Time error 2115" The macro or function set to the BeforeUpdate or
ValidationRule property for the fields is preventing Microsoft Access
from saving the data in the Field.

I'm not sure what I'm doing wrong as the SQL statement seems correct and the use of Form_BeforeUpdate seems to follow examples I have seen on the net.

I have checked the net, but don't understand thier solutions.

Any help would be much appreciated!

Thanks

robben is offline   Reply With Quote
Old 01-30-2008, 06:50 AM   #2
boblarson
Smeghead
 
boblarson's Avatar
 
Join Date: Jan 2001
Location: Oregon, USA
Posts: 32,068
Thanks: 97
Thanked 1,799 Times in 1,570 Posts
boblarson is a splendid one to behold boblarson is a splendid one to behold boblarson is a splendid one to behold boblarson is a splendid one to behold boblarson is a splendid one to behold boblarson is a splendid one to behold boblarson is a splendid one to behold
Are you sure the datatypes are correct (including length for text fields) for the tables?

Are you inserting to a SQL Server table (if so you need to make sure it has a primary key).

Those are just a couple of things I would check.
__________________

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
boblarson is offline   Reply With Quote
Old 01-30-2008, 07:00 AM   #3
robben
Registered User
 
Join Date: Jan 2008
Posts: 52
Thanks: 0
Thanked 0 Times in 0 Posts
robben is on a distinguished road
Thanks for your reply. Datatypes seem to be ok, and I'm not using SQL Server. The problem appears to occur when it reaches DoCmd.RunCommand acCmdSaveRecord should I take this line out and replace it with my manually created SQL which I shall write? DoCmd.RunCommand acCmdSaveRecord is called when it is a new record. Futher INSERT satetments are then used to populate other tables after the line DoCmd.RunCommand acCmdSaveRecord.

robben is offline   Reply With Quote
Old 01-30-2008, 07:38 AM   #4
robben
Registered User
 
Join Date: Jan 2008
Posts: 52
Thanks: 0
Thanked 0 Times in 0 Posts
robben is on a distinguished road
I have tired putting DoCmd.RunCommand acCmdSaveRecord in a seperate function and calling this function from within Form_BeforeUpdate. Although, it now gives me a new error message:
"The command or action 'SaveRecord' isn't available now." "Error 2046"
robben is offline   Reply With Quote
Old 01-30-2008, 09:30 AM   #5
robben
Registered User
 
Join Date: Jan 2008
Posts: 52
Thanks: 0
Thanked 0 Times in 0 Posts
robben is on a distinguished road
Trying to write the INSERT statement see below, although it gives me a syntax error (Would anyone have any ideas) Thanks:



DoCmd.RunSQL ("INSERT INTO Document_Table(Date, Location, Description, Entered_Date, Approval_Date, Available_Date, Keywords, Document_Number, File_Size, Document_ID)" & _
"VALUES('" & Me.Title & "', #" & Me.Date & "#, '" & Me.Location & "', '" & Me.Description & "', #" & Me.Entered_Date & "#, #" & Me.Approval_Date & "#, #" & Me.Available_Date & "#, '" & Me.Keywords & "', '" & Me.Document_Number & "', " & Me.File_Size & ", " & Me.Document_ID & ")")
robben is offline   Reply With Quote
Old 01-30-2008, 02:15 PM   #6
robben
Registered User
 
Join Date: Jan 2008
Posts: 52
Thanks: 0
Thanked 0 Times in 0 Posts
robben is on a distinguished road
Anyone know?
robben is offline   Reply With Quote
Old 01-30-2008, 02:28 PM   #7
boblarson
Smeghead
 
boblarson's Avatar
 
Join Date: Jan 2001
Location: Oregon, USA
Posts: 32,068
Thanks: 97
Thanked 1,799 Times in 1,570 Posts
boblarson is a splendid one to behold boblarson is a splendid one to behold boblarson is a splendid one to behold boblarson is a splendid one to behold boblarson is a splendid one to behold boblarson is a splendid one to behold boblarson is a splendid one to behold
First thing that jumps out at me is your use of the word DATE which is a reserved keyword. Rename that column in the table.

__________________

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
boblarson is offline   Reply With Quote
Old 01-30-2008, 02:32 PM   #8
RuralGuy
AWF VIP
 
RuralGuy's Avatar
 
Join Date: Jul 2005
Location: @ 8300' in the Colorado Rockies
Posts: 13,730
Thanks: 5
Thanked 298 Times in 290 Posts
RuralGuy is just really nice RuralGuy is just really nice RuralGuy is just really nice RuralGuy is just really nice RuralGuy is just really nice
Quote:
Originally Posted by robben View Post
I have tired putting DoCmd.RunCommand acCmdSaveRecord in a seperate function and calling this function from within Form_BeforeUpdate. Although, it now gives me a new error message:
"The command or action 'SaveRecord' isn't available now." "Error 2046"
The reason you are in the Form's BeforeUpdate event is because the record is being saved. You are trying to save it again inside the save routine.
__________________
(RG for short) aka Allan Bunch Previous MS Access MVP acXP, ac07, ac10, ac13 - WinXP Pro, Win7 Pro, Win10 Pro
Please post back to this Forum so all may benefit.
Teaching is not filling a bucket but lighting a fire.
RuralGuy is offline   Reply With Quote
The Following User Says Thank You to RuralGuy For This Useful Post:
vicsar (11-07-2012)
Old 01-30-2008, 02:38 PM   #9
boblarson
Smeghead
 
boblarson's Avatar
 
Join Date: Jan 2001
Location: Oregon, USA
Posts: 32,068
Thanks: 97
Thanked 1,799 Times in 1,570 Posts
boblarson is a splendid one to behold boblarson is a splendid one to behold boblarson is a splendid one to behold boblarson is a splendid one to behold boblarson is a splendid one to behold boblarson is a splendid one to behold boblarson is a splendid one to behold
Quote:
Originally Posted by RuralGuy View Post
The reason you are in the Form's BeforeUpdate event is because the record is being saved. You are trying to save it again inside the save routine.
Duh...sheesh - can't I read...I guess not....

But I would still rename the field named DATE.
__________________

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
boblarson is offline   Reply With Quote
Old 01-30-2008, 10:49 PM   #10
robben
Registered User
 
Join Date: Jan 2008
Posts: 52
Thanks: 0
Thanked 0 Times in 0 Posts
robben is on a distinguished road
Would anyone know whay I'm getting the following error?

"Run-Time error 2115" The macro or function set to the BeforeUpdate or
ValidationRule property for the fields is preventing Microsoft Access
from saving the data in the Field.

Thanks
robben is offline   Reply With Quote
Old 01-30-2008, 11:09 PM   #11
boblarson
Smeghead
 
boblarson's Avatar
 
Join Date: Jan 2001
Location: Oregon, USA
Posts: 32,068
Thanks: 97
Thanked 1,799 Times in 1,570 Posts
boblarson is a splendid one to behold boblarson is a splendid one to behold boblarson is a splendid one to behold boblarson is a splendid one to behold boblarson is a splendid one to behold boblarson is a splendid one to behold boblarson is a splendid one to behold
Quote:
Originally Posted by robben View Post
Would anyone know whay I'm getting the following error?

"Run-Time error 2115" The macro or function set to the BeforeUpdate or
ValidationRule property for the fields is preventing Microsoft Access
from saving the data in the Field.

Thanks
Did you not see Rural Guy's response above?

http://www.access-programmers.co.uk/...97&postcount=8

You can't use a Save command when the record is already in the process of being saved which is what happens when the Before Update event is fired. So, to say it explicitly take out the Save command from the Before Update event code.
__________________

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
boblarson is offline   Reply With Quote
Old 02-02-2008, 12:38 AM   #12
robben
Registered User
 
Join Date: Jan 2008
Posts: 52
Thanks: 0
Thanked 0 Times in 0 Posts
robben is on a distinguished road
Apologies I didnít see your thread. Thanks for your help, I have now got it working.
robben is offline   Reply With Quote
Old 02-02-2008, 05:40 AM   #13
missinglinq
AWF VIP
 
missinglinq's Avatar
 
Join Date: Jun 2003
Location: Richmond (Virginia that is!)
Posts: 6,024
Thanks: 11
Thanked 640 Times in 603 Posts
missinglinq is just really nice missinglinq is just really nice missinglinq is just really nice missinglinq is just really nice missinglinq is just really nice
And be sure to take Bob's advice about renaming your "Date" field.

__________________
The Devil's in the Details!
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.


(All code solutions tested in Access 2003/2007, before posting, unless otherwise noted.)
missinglinq is offline   Reply With Quote
Reply

Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Form BeforeUpdate event wh00t Forms 2 01-04-2008 07:42 AM
How Can I Branch To The BeforeUpdate Event? Curious Modules & VBA 2 08-23-2007 04:26 PM
Using Beforeupdate Cancel jaydwest Modules & VBA 1 02-25-2006 02:33 PM
BeforeUpdate Problem. skea General 6 03-31-2005 05:18 AM
Cancel BeforeUpdate Event wjoc1 Modules & VBA 5 07-23-2004 03:24 AM




All times are GMT -8. The time now is 09:41 PM.


Microsoft Access Help
General
Tables
Queries
Forms
Reports
Macros
Modules & VBA
Theory & Practice
Access FAQs
Code Repository
Sample Databases
Video Tutorials

Sponsored Links

How to advertise

Media Kit


Powered by vBulletin®
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
(c) copyright 2017 Access World