BeforeUpdate Error 2115 (1 Viewer)

robben

Registered User.
Local time
Yesterday, 17:35
Joined
Jan 27, 2008
Messages
52
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
 

boblarson

Smeghead
Local time
Yesterday, 17:35
Joined
Jan 12, 2001
Messages
32,059
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.
 

robben

Registered User.
Local time
Yesterday, 17:35
Joined
Jan 27, 2008
Messages
52
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

Registered User.
Local time
Yesterday, 17:35
Joined
Jan 27, 2008
Messages
52
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

Registered User.
Local time
Yesterday, 17:35
Joined
Jan 27, 2008
Messages
52
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 & ")")
 

boblarson

Smeghead
Local time
Yesterday, 17:35
Joined
Jan 12, 2001
Messages
32,059
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.
 

RuralGuy

AWF VIP
Local time
Yesterday, 18:35
Joined
Jul 2, 2005
Messages
13,826
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.
 

boblarson

Smeghead
Local time
Yesterday, 17:35
Joined
Jan 12, 2001
Messages
32,059
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.
 

robben

Registered User.
Local time
Yesterday, 17:35
Joined
Jan 27, 2008
Messages
52
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
 

boblarson

Smeghead
Local time
Yesterday, 17:35
Joined
Jan 12, 2001
Messages
32,059
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/forums/showpost.php?p=668497&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.
 

robben

Registered User.
Local time
Yesterday, 17:35
Joined
Jan 27, 2008
Messages
52
Apologies I didn’t see your thread. Thanks for your help, I have now got it working.
 

missinglinq

AWF VIP
Local time
Yesterday, 20:35
Joined
Jun 20, 2003
Messages
6,423
And be sure to take Bob's advice about renaming your "Date" field.
 

Users who are viewing this thread

Top Bottom