new record uses previous record data

ianking

Registered User.
Local time
Today, 18:18
Joined
Mar 15, 2008
Messages
29
new record to use previous record data

Hi,

I'm trying to set up a form for user data entry, where a field on the form automatically contains the same data as the previous entry. This would save time where there are a number of records to be entered where this particular field remains the same. I can't use default value because it won't always be the same, and I'm guessing it will be code on the after update event, but am unsure how to get the contents of the field from the previous record.

thanks for any help,

Ian
 
Last edited:
effectively in the before update event of the previous record, you save the fields you want to bring ofrward, and then in the current event of the new record, set the fields to those values - some developers use the controls tag property to save the values, or you can use variables
 
Simple Software Solutions

Hi

When you are in the form and you are on a new record and you want the values from the previous record to appear in the same field for the new one press the Ctrl+' (Apostophe) key. Hey Presto... the previous data appears. This used be done via the F8 key but Access changed this functionality with Access 2000 onwards.

CodeMaster::cool:
 
thanks

thanks - how do I identify the contents of the text box in code?

Private Sub Form_BeforeUpdate(Cancel As Integer)

prefix.tag = prefix.text (I know this is incorrect but it hopefully explains what I want to do)

End Sub


Private Sub Form_current()

prefix.text = prefix.tag

End Sub_current
 
I'm confused by

"I can't use default value because it won't always be the same."

Using the default value is the standard way of doing this; after entering a number of records, if a value changes, you simply edit the field to reflect the new value. Any method you choose to do this is going top have the same "problem" i.e eventually the saved value will not the one you then want, and you'll have to edit it.
 
Why default value is no use

I'm envisaging a situation where a user is entering a sequence of records - all of which have a particular field the same - the value of this field will change with the next sequence of records, but there is no way of predicting what that value will be. I was just hoping to save time on data entry.
 
As I said before, you use the AfterUpdate to assign the current value to the default, and when one sequence ends, you overwrite the field with the new value. Entering the new dat once out of ten or twenty or more records obviously is going to be faster than entering it for every record.
 
making default value the current value

Thanks.

This is the code I've used, but it isn't working for me:

Private Sub enterprefix_AfterUpdate()

DefaultValue = Me.enterprefix.Value

End Sub
 
You can try this

Option Compare Database
Public k As String

Private Sub Form_AfterInsert()
k = Me.fieldname
End Sub

Private Sub Form_BeforeInsert(Cancel As Integer)
Me.fieldname = k
End Sub
 
Thanks.

This is the code I've used, but it isn't working for me:

Private Sub enterprefix_AfterUpdate()

DefaultValue = Me.enterprefix.Value

End Sub

The reason the above code didn't work was you were assigning the current value of enterprefix to DefaultValue which is a property, not to a control/field!

DefaultValue = Me.enterprefix.Value

should have been

enterprefix.DefaultValue = Me.enterprefix.Value

Glad you got it working for you!
 
Last edited:

Users who are viewing this thread

Back
Top Bottom