Macro or Function set to the BeforeUpdate (1 Viewer)

gaidheal

Registered User.
Local time
Yesterday, 23:21
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.
 

gaidheal

Registered User.
Local time
Yesterday, 23:21
Joined
Oct 7, 2008
Messages
18
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.
 

RuralGuy

AWF VIP
Local time
Today, 00:21
Joined
Jul 2, 2005
Messages
13,825
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.
 

GinaWhipp

AWF VIP
Local time
Today, 02:21
Joined
Jun 21, 2011
Messages
5,899
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
 

gaidheal

Registered User.
Local time
Yesterday, 23:21
Joined
Oct 7, 2008
Messages
18
Re: Macro or Function set to the BeforeUpdate...

Thanks, that did the trick.
 

Users who are viewing this thread

Top Bottom