Copying a previous entry

G

Guest

I am working up a simple inventory system (Access 2002) for the boss.
Eventually we will use a barcode as every item's unique identifier. What he
wants me to do is to allow the system to repeat all the info on our input
form except for the barcode. For instance, item one: office chair, item two:
office chair. What kind of coding do I need to move the form to a new record
but keep all the previous infor except for the barcode number?
 
G

Guest

Dan,

A simple way to do this is to use the AfterUpdate event of each field you
wish to repeat to set its DefaultValue:

Me![YourTextbox].DefaultValue = Me![YourTextbox]

This will work for the first manually entered record and subsequent records
entered in a given session. To pick up the values of the last record entered
in a previous session, you can use the form's On Open event to move to the
last record, copy its values to an array, move to a new record, and copy the
array values to the controls:

Dim avarFieldValues(n) As Variant
' n is the number of fields to copy - 1, i.e., the highest subscript of the
array

Dim strDocName As String
strDocName = "Your Form"

' Move to last record
DoCmd.GoToRecord acDataForm, strDocName, acLast

' Assign array values
avarFieldValues(0) = Me![YourFirstControl]
avarFieldValues(1) = Me![YourSecondControl]
.... other array values assigned here
avarFieldValues(n) = Me![YourLastControl]

' Move to new record
DoCmd.GoToRecord acDataForm, strDocName, acNewRec

' Assign values from array
Me![YourFirstControl] = avarFieldValues(0)
Me![YourSecondControl] = avarFieldValues(1)

' Because the AfterUpdate events of the controls are not triggered by
' these assignments, assign the default values.
Me![YourFirstControl].DefaultValue = Me![YourFirstControl]
Me![YourSecondControl].DefaultValue = Me![YourSecondControl]
... others here
Me![YourLastControl].DefaultValue = Me![YourLastControl]

Hope that helps.
Sprinks
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top