Get field value from the previous record

theSizz

Registered User.
Local time
Today, 18:42
Joined
Nov 29, 2002
Messages
34
I want to get the value from FieldA in the previous record of a table and copy it into a new record in the same table, but in a different field named FieldB.

I've put this line of code in the declaration section of a module :

Global gGetNumber As Double

Now in the form that is linked to the table that has the data, I entered in the OnOpen event of the form the followingline of code:

gGetNumber = Me! [txtFieldA]

Now in the OnCurrent event of the same form I entered this code:

If Me.Form.NewRecord = True Then
Me! [txtFieldB] = gGetNumber
End If

The code results in a 0 (zero) being entered in FieldB of the new record, it does not copy the value of FieldA which has a number in it that is not zero.

What am I doing wrong.
Can anyone help me ?

Thanks
 
You should be able to edit the field to suit your needs. This is how I do it...

Making the next field in records default to the last record.


In the After Update event of the UserName field put code like this:

Me![UserName].Tag = Me![UserName].Value

In the On Enter Event of the same field put code like this:

If Not Me.NewRecord Then Exit Sub
If Not (IsNull(Me![UserName].Tag) Or Me![UserName].Tag = "") Then
Me![UserName].Value = Me![UserName].Tag
End If

The UserName will not carry over into your next session with the form but will work as long as the form is open....
 
Something like this:

In the After Update event of the txtFieldA field put code like this:

Me![txtFieldA].Tag = Me![txtFieldA].Value

In the On Enter Event of the txtFieldB field put code like this:

If Not Me.NewRecord Then Exit Sub
If Not (IsNull(Me![txtFieldA].Tag) Or Me![txtFieldA].Tag = "") Then
Me![txtFieldB].Value = Me![txtFieldA].Tag
End If

Dave
 
Thanks Dave,
Sweet and simple.
I appreciate the help.
 

Users who are viewing this thread

Back
Top Bottom