Copy from previous record

MaleNurse325

Registered User.
Local time
Yesterday, 19:20
Joined
Jan 11, 2016
Messages
72
I have a simple form with a single field that I need to be able to copy to a new entry. The Field is called BatchNum. I want to be able to copy this for several records and then edit it so subsequent records are updated with the new data.

Help me please :banghead:
 
The easiest route is to set the default value for the single field to the value of the record you just entered. You can do this with a simple bit of VBA attached to the after update property of the field. So assuming your textbox Control is called txtBatchNum something like

Private Sub txtBatchNum_AfterUpdate()

Me.txtBatchNum.DefaultValue = Me.txtBatchNum


End Sub
 
Right idea but it's not quite that simple:

Code:
Private Sub YourControlName_AfterUpdate()
   Me.YourControlName.DefaultValue = """" & Me.YourControlName.Value & """"
End Sub
This syntax is valid for Text, Number, DateTime and Boolean Datatypes.

You’ll need to do this for each Control that you want to 'carry forward.'

Linq ;0)>
 
The code works to carry the data from one form to the next but if I change the value in the filed it reverts back to the original value. I need to be able to update the value then carry that forward for future values
 
Not sure I understand...if you edit the value that was placed in the Field, when the new record was instantiated, it should then become the new DefaultValue for that Control and, once again, be carried forward until it is again changed, or the Form or Access itself closed.

The only way I can think of that this wouldn't happen would be if you were 'changing' the value using code, as opposed to physically changing the data, i.e. via keyboard input.
In that case, the Control's AfterUpdate wouldn't fire and hence, the DefaultValue wouldn't change.

Linq ;0)>
 
Hi, I managed to sort this issue by adding this to the OnOpen

Private Sub Form_Open(Cancel As Integer)
ID = DMax("DailyWater", "tblDailyWater")
DoCmd.GoToRecord , , acNewRec
CalibNo = DLookup("CalibNo", "tblDailyWater", "DailyWater=" & ID)
End Sub


:)
 

Users who are viewing this thread

Back
Top Bottom