Macro or Function set to the BeforeUpdate

gaidheal

Registered User.
Local time
Today, 11:45
Joined
Oct 7, 2008
Messages
18
I am getting the following error: "The macro or function set to the BeforeUpdate or ValidationRule property for this field is preventing [dbName] from saving the data in the field."

I am trying to increment the value of a field on a form when a new record is created. I know having an Autonumber field will accomplish the same purpose, and in fact we do have such a field. But a second field was needed that could be modified/reset as needed.

I created the following code in the AfterInsert property of the form:


Private Sub Form_AfterInsert()
On Error GoTo Err_AfterInsert

Dim Current_count As Integer

Current_count = DMax("[workrequestnumber]", "basic_data")
Me.WorkRequestNumber = Current_count + 1

Exit_AfterInsert:
Exit Sub

Err_AfterInsert:
MsgBox Err.Description
Resume Exit_AfterInsert

End Sub

The Autonumber appears as soon as I enter any data, but this seconday field shows nothing until I enter data into a second field, and that's when the error occurs.

Any ideas would be greatly appreciated.
 
Macro or Function set to the BeforeUpdate...

I am getting the following error: "The macro or function set to the BeforeUpdate or ValidationRule property for this field is preventing [db] from saving the data in the field."

We have an autonumber in the table the updates as soon as any data is entered into a new record on the form. But we also need a seconday number field that is not an autonumber, but which will increment when a new record is created, just like the autonumber does,

I had the code set to the AfterInsert property of the form, and got the error after entering data into one or two fields.

Here's my code:


Private Sub Form_AfterInsert()
On Error GoTo Err_AfterInsert

Dim Current_count As Integer

Current_count = DMax("[workrequestnumber]", "basic_data")
Me.WorkRequestNumber = Current_count + 1

Exit_AfterInsert:
Exit Sub

Err_AfterInsert:
MsgBox Err.Description
Resume Exit_AfterInsert

End Sub

Any ideas would be appreciated.
 
Re: Macro or Function set to the BeforeUpdate...

You are going to want to use the BeforeUpdate event of the Form for such a task.
 
Thar code should be on the Before_Insert event of the form. You can also simplify by...

Code:
Private Sub Form_BeforeInsert()
On Error GoTo Err_BeforeInsert
 
 
Me.WorkRequestNumber =DMax("[workrequestnumber]", "basic_data")+ 1
 
Exit_BeforeInsert:
Exit Sub
 
Err_BeforeInsert:
MsgBox Err.Description
Resume Exit_BeforeInsert
 
Re: Macro or Function set to the BeforeUpdate...

Thanks, that did the trick.
 

Users who are viewing this thread

Back
Top Bottom