Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Carry a value forward to the next record

How to

Carry a value forward to the next record

by  Terpsfan  Posted    (Edited  )
I have found it helpful to carry values forward to the next record on a form. This is how I do it. On the form's after update event you set the control's default value to the control's present value.

If you want to do this for multiple controls, you want to set the tag property of each control to CarryForward, then iterate through each control on the form.

I did not see an FAQ on this so I submitted it. Sorry if I am duplicating another post.


'For individual controls
Private Sub Form_AfterUpdate()
'Setup error handling
On Error GoTo Form_AfterUpdate_Err

'Carry the batch number forward
Me.Controls("controlname").DefaultValue = """" & Me.Controls("controlname").Value & """"

Form_AfterUpdate_Exit:
Exit Sub
Form_AfterUpdate_Err:
'Alert the user that an error has occurred
Call ErrorHandler(Err.Number, Err.Description, "frmACCT.Form_AfterUpdate")

Resume Form_AfterUpdate_Exit

End Sub

'For multiple controls

Private Sub Form_AfterUpdate()
'Setup error handling
Dim ctl as control
On Error GoTo Form_AfterUpdate_Err

'Carry the batch number forward for each control
For Each ctl in me.Controls
If ctl.Tag = "CarryForward"
ctl.DefaultValue = """" & ctl.Value & """"
End If
Next ctl
Form_AfterUpdate_Exit:
Set ctl = Nothing
Exit Sub
Form_AfterUpdate_Err:
'Alert the user that an error has occurred
Call ErrorHandler(Err.Number, Err.Description, "frmACCT.Form_AfterUpdate")

Resume Form_AfterUpdate_Exit

End Sub

Register to rate this FAQ  : BAD 1 2 3 4 5 6 7 8 9 10 GOOD
Please Note: 1 is Bad, 10 is Good :-)

Part and Inventory Search

Back
Top