PDA

View Full Version : [SOLVED:] Error with Before Update



Charity
03-16-2006, 07:59 AM
Hi,

I am getting a weird error that I have no idea how to fix. After the user enters the number of days a house has been worked on, I want to determine if the # of days in a house exceeds the number of days allowed for that house. I am able to get the calculation to work, but I get the following error:

Runtime error 2115:
The macro or function set to the BeforeUpdate or ValidationRule property for this field is preventing Microsoft Office Access from saving data in the field.

However, there is not anything in the BeforeUpdate or ValidationRule properties for the field. Just to be sure I even created a brand new field and I got the same answer. What I discovered is that access is automatically creating a BeforeUpdate event for the field. Does anyone know what might be happening?

Here is my code:

Private Sub Number_of_Days_in_House_AfterUpdate()
'to determine if the number of days in a house exceeds the number of days allowed
'returns a yes if Days_In_House is greater than Days_Allowed
Dim Days_Allowed As Integer
Dim Days_In_House As Integer
Dim Result As String
Me.Number_of_Days_in_House.SetFocus
Days_In_House = CInt(Me.Number_of_Days_in_House.Text)
Form_FRM_DMUR.Number_of_Days_Allowed.SetFocus
Days_Allowed = CInt(Form_FRM_DMUR.Number_of_Days_Allowed.Text)
If Days_In_House <= Days_Allowed Then Result = "No" Else: Result = "Yes"
Me.Exceeds_Days.SetFocus
Me.Exceeds_Days.Text = Result
End Sub

The last line is where I get the error.

Any help would be great, I'm stumped!
-Charity :help

geekgirlau
03-16-2006, 10:15 PM
You don't need to set the focus to a control in order to change it's value. Try this (I've also used "nz" to cope with possible null values)



Private Sub Number_of_Days_in_House_AfterUpdate()
'to determine if the number of days in a house exceeds the number of days allowed
'returns a yes if Days_In_House is greater than Days_Allowed
Dim Days_Allowed As Integer
Dim Days_In_House As Integer
Dim Result As String
Days_In_House = Nz(CInt(Me.Number_of_Days_in_House), 0)
Days_Allowed = Nz(CInt(Form_FRM_DMUR.Number_of_Days_Allowed), 0)
If Days_In_House <= Days_Allowed Then Result = "No" Else: Result = "Yes"
Me.Exceeds_Days = Result
End Sub

Charity
03-21-2006, 12:37 PM
The reason I included the set focus is because I got an error message saying that Access could not reference a field unless that field had the focus. When I added the set focus statement I stopped getting the error message. Is there a better way to avoid that error?

geekgirlau
03-23-2006, 08:30 PM
That's because you were using "Me.Number_of_Days_in_House.Text" - my code does not use the Text property.

Charity
03-24-2006, 12:29 PM
Thanks for your help! That solved my problem.