copying data from one input form to the next

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have a data entry form on which when some of the fields are updated e.g.
date, product they remain the same for the next entry.

Therefore i would like to know how to set the default value of these fields
to the value in the previous record so that when this is the case users can
TAB through the field and only change the fields in the form that have
changed.

Regards

Adrian
 
Hi, Sandy.

To set the default on loading the form, you can use the OnLoad event to set
the initial default values by moving the the last record, reading the current
values into an array, moving to a new record, and setting the default
properties to the read values:

Dim ctl As Control
Dim intIndex as Integer
Dim varMyValues(MyNumberofFields) As Variant

DoCmd.GoToRecord , , acLast
intIndex = 0

For Each ctl In Me.Controls
Select Case ctl.ControlType
Case acTextbox, acOptionGroup, acCheckbox, acCombobox, acListBox
varMyValues(intIndex) = ctl.Value
intIndex = intIndex + 1
Case Else
' Do nothing, it's a label or image, etc.
End Select
End For

' Go to new rec
DoCmd.GoToRecord , , acNewRec

intIndex = 0
For Each ctl In Me.Controls
Select Case ctl.ControlType
Case acTextbox, acOptionGroup, acCheckbox, acCombobox, acListBox
ctl.DefaultValue = varMyValues(intIndex)
intIndex = intIndex + 1
Case Else
' Do nothing, it's a label or image, etc.
End Select
End For

To reset the default after the user has changed a value, use the AfterUpdate
event of the control:

Me!MyControl.DefaultValue = Me!MyControl.DefaultValue

Hope that helps.
Sprinks
 
Back
Top