Default to previous record value

  • Thread starter Thread starter Fred
  • Start date Start date
F

Fred

In a form, is there a way to set the default value on a new record = to the
value of the previous record.

For example if I'm entering Automobiles and Make was a field. If I had 100
Chevys in a row I'd like the Make field to default to Chevy. Then if I
change it to Ford, it will automatically set the default to Ford.

TIA,
Fred
 
Hello Allen

I try to implement the beforeInsert event, I created the module and copied
the code, but get an compile error saying expected variable or procedure,
not project in:

Private Sub Form_BeforeInsert(Cancel As Integer)
Call CarryOver(Me)

End Sub

What goes wrong here?
Do I also need to put an event in the related txtbox?

Herman
 
Sounds like a name clash.

What name did you use to save the module? It must be different from the name
of the function, e.g. you can call it "basCarryOver", but not "CarryOver".

What is the name of your project?
From any code window, look on the Tools menu.
It will show you the properties for the project name.
Again, the project name cannot be the same as the function name.
 
Hello Allen

You where right I needed to change the project name
It works now. Is it possible to do this exersize for 1 field only?

Herman
 
Sure. Instead of looping through the controls, you can just the the Value of
the control by name.
 
Hello Allen

Sorry to disturb you again

I tried:
Private Sub Form_BeforeInsert(Cancel As Integer)
Call CarryOver(Me.txtwaarde)
End Sub

and
Private Sub Form_BeforeInsert(Cancel As Integer)
Call CarryOver(Me.txtwaarde.value)
End Sub

Both gives an error Do I need to put a dim statement for textwaarde?

Herman
 
No, you won't be able to use the CarryOver function as it stands to do this.

Insted, set the form's BeforeInsert property to:
[Event Procedure]
Click the Build button (...) beside this.
Access opens the code window.
Put your code in there.

The other alternative is the previous link I gave you, which uses the
AfterUpdate event of the control itself to set the Default Value.
 
Back
Top