Ms Access Runtime Error 2115
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site About Us Learn more about Stack Overflow the company Business Learn more about hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 6.2 million programmers, just like you, helping each other. Join them; it only takes a minute: Sign up BeforeUpdate issue - Runtime error 2115 up vote 0 down vote favorite I have written the following query: Private Sub Size_Sqft_BeforeUpdate(Cancel As Integer) Me!Size_Sqft = Nz(Me!Size_Sqft, 0) End Sub But while removing the zero in the field to make it null, I am getting the following error: Runtime error 2115 Macro and function set to before update and validation rule property for this field is preventing manual data entry screen for company from saving the data in the field. ms-access vba access-vba share|improve this question edited Nov 26 '15 at 11:55 w5m 1,31731640 asked Oct 12 '09 at 10:33 SmartestVEGA 1,892124072 add a comment| 2 Answers 2 active oldest votes up vote 2 down vote accepted You have to put that code in the AfterUpdate event of that field. share|improve this answer answered Oct 12 '09 at 11:43 Tony Toews 7,02511324 add a comment| up vote 1 down vote I know this is an old thread, and has already been answered, but there is another solution that doesn't require several writes back to your database. I'm adding it in case someone else comes across this question. Private Sub ControlName_BeforeUpdate(Cancel as integer) If isValid(Me.ControlName.Value) = False Then Cancel = True Me.ControlName.Undo End If End Sub Private Function isValid(ByVal...) as boolean ' validate control value here End Function share|improve this answer edited Nov 26 '15 at 11:30 w5m 1,31731640 answered Jan 21 '14 at 16:46 RubberDuck 5,69822458 add a comment| Your A
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site About Us Learn more about Stack Overflow the company Business Learn more about hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 6.2 million programmers, just like you, helping each other. Join them; it only takes a minute: Sign up Runtime error 2115 at Access 2013 up vote 1 down vote favorite My Access database is linked to http://stackoverflow.com/questions/1553833/beforeupdate-issue-runtime-error-2115 my SQL Server 2008. I'm trying to validate if the value entered into a textbox field (called diverNo) is a number (only numbers are allowed in this field). I want it to be validated as soon as the user leaves the field, and if the user tries to put any character which is not a number, the field will be cleaned: Private Sub Form_Error(DataErr As Integer, Response As Integer) If DataErr = http://stackoverflow.com/questions/26426425/runtime-error-2115-at-access-2013 2113 Then Response = acDataErrContinue MsgBox ("Only numbers are allowed in Diver Number") Me.diverNo = "" ' <- this line cause the error Exit Sub End If End Sub I get Runtime-error 2115 which states "The macro or function set to the BeforeUpdate or ValidationRule property for this field is preventing Microsoft Office Access from saving the data in the field." Any suggestions to fix this? ms-access access-vba share|improve this question asked Oct 17 '14 at 13:44 Ofer Gozlan 808 In the BeforeUpdate method, the value cannot be changed. –Mark C. Oct 17 '14 at 14:43 add a comment| 2 Answers 2 active oldest votes up vote 1 down vote Calling the Undo method and setting Cancel to True in the BeforeUpdate handler seems to work. Private Sub diverNo_BeforeUpdate(Cancel As Integer) If IsNumeric(Me.diverNo) = False Then Cancel = True 'stops the record from being saved. Me.diverNo.Undo 'only the control itself is affected. MsgBox ("Please only enter a number") End If End Sub BeforeUpdate is good if you also want to evaluate an old vs new value being entered into a field (for a bound field). This is lost in the AfterUpdate method, as the record has already updated. share|improve this answer answered Oct 17 '14 at 15:13 Mark C. 3,58631237 add a
Groups Pictures & Albums Members List Calendar Search Forums Show Threads Show Posts Tag Search Advanced Search Find All Thanked Posts Go to Page... Thread Tools Rating: Display Modes 09-09-2009, 02:48 PM http://www.access-programmers.co.uk/forums/showthread.php?t=179234 #1 Radioactiveduck Registered User Join Date: Sep 2009 Posts: 9 Thanks: 0 Thanked 0 Times in 0 Posts Run-time error '2115' I have a form with the following fields and data types: Date: text in "mmm dd, yyyy" format JAF: checkbox EFS: checkbox txt_ChAttn: textbox, generic format Note: textbox, generic format Basically, I've written code that does an AfterUpdate whenever JAF or EFS are checked or unchecked. It writes ms access "John Doe" or "Jane Doe" into the txt_ChAttn textbox depending on which one is checked. I get the following vba error whenever it runs, however: Run-time error '2115': the macro or function set to the BeforeUpdate or ValidationRule property for this field is preventing Microsoft Office Access from saving the data in the field. Now, I checked the results, and it actually is updating the txt_ChAttn textbox correctly, but it still ms access runtime throws this error every time you check or uncheck the checkboxes. Here is the code for the updates: Private Sub EFS_AfterUpdate() If EFS = -1 Then If JAF = -1 Then Me.txt_ChAttn.SetFocus Me.txt_ChAttn.Text = "John Doe, Jane Doe" Me.Refresh Else Me.txt_ChAttn.SetFocus Me.txt_ChAttn.Text = "John Doe" Me.Refresh End If Else If JAF = -1 Then Me.txt_ChAttn.SetFocus Me.txt_ChAttn.Text = "Jane Doe" Me.Refresh Else Me.txt_ChAttn.SetFocus Me.txt_ChAttn.Text = "" Me.Refresh End If End If End Sub Private Sub JAF_AfterUpdate() If EFS = -1 Then If JAF = -1 Then Me.txt_ChAttn.SetFocus Me.txt_ChAttn.Text = "John Doe, Jane Doe" Me.Refresh Else Me.txt_ChAttn.SetFocus Me.txt_ChAttn.Text = "John Doe" Me.Refresh End If Else If JAF = -1 Then Me.txt_ChAttn.SetFocus Me.txt_ChAttn.Text = "Jane Doe" Me.Refresh Else Me.txt_ChAttn.SetFocus Me.txt_ChAttn.Text = "" Me.Refresh End If End If End Sub Depending on which conditions are met, it always highlights the "Me.txt_ChAttn.Text =" line, regardless of which combination of checked/unchecked the textboxes fall under. Any ideas on what's causing this error, and how I can get rid of it? As I said, it is updating the textbox correctly. EDIT: I can't seem to force it to post the code with the correct text spacing, so it may look a bit sloppy. Last edited by Radioactiveduck; 09-09-2009 at 02:57 PM. Radioactiveduck View Public Profile F