PDA

View Full Version : Get field value from the previous record



theSizz
01-20-2007, 08:06 PM
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

adam_r_davis
01-20-2007, 08:42 PM
...

adam_r_davis
01-20-2007, 08:44 PM
When I put this into a similar form it never enters the if statement.
I have a similar function that is solved by a hidden text field on the form that initialises to "" therefore is skipped on the first OnCurrent but then retains the old ID value so I can purge stuff relating to the old record when I go to the next record:

Private Sub Form_Current()
SaveChanges
txtCurrentID = Me.Recordset!PersonID

End Sub


Private Sub SaveChanges(Optional SaveByDefault As Boolean)
' Other stuff
If Nz(txtCurrentID, "") <> "" Then
ReleaseLock "tPeople", CInt(txtCurrentID)
End If
End Sub