Save Old Index

E

Eric

I have an amend button that allows me to edit and save records. I
want to create a new field called "OldIndex" which stores the previous
index in the new record when the amend button is clicked. This way, I
can go back and see the old records that have been amended. How would
I go on doing this?
 
A

Allen Browne

Access doesn't provide a way to do that, but if all changes are made through
a form, you can use the form's events to achieve it.

I take it you are adding a new field to the table, and this OldIndex field
stores just the most recent change. Use the BeforeUpdate event procedure of
the form to copy the value into the field.

Example:
Private Sub Form_BeforeUpdate(Cancel As Integer)
With Me.[Field1])
If .Value <> .OldValue Then
Me.OldIndex = .Value
End If
End With
End Sub

Replace Field1 with your field name.
 
E

Eric

Access doesn't provide a way to do that, but if all changes are made through
a form, you can use the form's events to achieve it.

I take it you are adding a new field to the table, and this OldIndex field
stores just the most recent change. Use the BeforeUpdate event procedure of
the form to copy the value into the field.

Example:
Private Sub Form_BeforeUpdate(Cancel As Integer)
With Me.[Field1])
If .Value <> .OldValue Then
Me.OldIndex = .Value
End If
End With
End Sub

Replace Field1 with your field name.

--
Allen Browne - Microsoft MVP. Perth, Western Australia
Tips for Access users -http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.


I have an amend button that allows me to edit and save records. I
want to create a new field called "OldIndex" which stores the previous
index in the new record when the amend button is clicked. This way, I
can go back and see the old records that have been amended. How would
I go on doing this?


Allen thanks for the response. I created an 'OldIndex' field in the
table and two textboxes on the form, 'Index' and 'OldIndex'. I used
the code you provided be below and it's not storing the OldIndex in
the textbox. Could you tell me what I'm doing wrong? Thanks.


Private Sub Form_BeforeUpdate(Cancel As Integer)
With Me.OldIndex
If .Value = .OldValue Then
Me.OldIndex = .Value
End If
End With
End Sub
 
A

Allen Browne

Your code is not doing anything, because it is not examining the real field
(which I think is called Index.)

Replace:
With Me.OldIndex
with:
With Me.[Index]

BTW, Index is not a good name for a field, as it is a reseved word. For a
list of the names to avoid, see:
http://allenbrowne.com/AppIssueBadWord.html

--
Allen Browne - Microsoft MVP. Perth, Western Australia

Reply to group, rather than allenbrowne at mvps dot org.

Eric said:
Access doesn't provide a way to do that, but if all changes are made
through
a form, you can use the form's events to achieve it.

I take it you are adding a new field to the table, and this OldIndex
field
stores just the most recent change. Use the BeforeUpdate event procedure
of
the form to copy the value into the field.

Example:
Private Sub Form_BeforeUpdate(Cancel As Integer)
With Me.[Field1])
If .Value <> .OldValue Then
Me.OldIndex = .Value
End If
End With
End Sub

Replace Field1 with your field name.

--
Allen Browne - Microsoft MVP. Perth, Western Australia
Tips for Access users -http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.


I have an amend button that allows me to edit and save records. I
want to create a new field called "OldIndex" which stores the previous
index in the new record when the amend button is clicked. This way, I
can go back and see the old records that have been amended. How would
I go on doing this?


Allen thanks for the response. I created an 'OldIndex' field in the
table and two textboxes on the form, 'Index' and 'OldIndex'. I used
the code you provided be below and it's not storing the OldIndex in
the textbox. Could you tell me what I'm doing wrong? Thanks.


Private Sub Form_BeforeUpdate(Cancel As Integer)
With Me.OldIndex
If .Value = .OldValue Then
Me.OldIndex = .Value
End If
End With
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top