.undo .OldValue problem

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have a form which has a check box that will replace a comment in a field
called STATUS in my table. Before my form is opened, the STATUS field already
has a comment in it. What I am having problem with, is to restore the
original STATUS comment if the event the user choose to uncheck the check box
from the form before it close it (one is close I don't care about undo).
me.undo does the job however it undo every change to the form. I have tried

Me!Status.undo
me.status.undo and
Me!Satatus.oldvalue

Dim OriginalValue As String
OriginalValue = Me!Status
me.Status.oldvalue
Me!Status = OriginalValue

and nottthing seems to work. I am getting very frustrated Can anyone help?
The code I have is a follow:

Private Sub ynFromZone_Click()

Dim OriginalValue As String
OriginalValue = Me!Status

If Me!ynFromZone = True Then
Me!tFromZone = Now
Me!dFromZone = Date
Me!Status = "Pending Assignment since " & Date
Me.Refresh

Else

Me!Status = OriginalValue
Me!ynFromZone = False
Me!tFromZone = Null
Me!dFromZone = Null

Me.Refresh

End If
End Sub
 
FYI: I am not sure if it makes any difference or not, the STATUS field it is
available as control in my form but it is not a field showing in my form.
 
I would recommend renaming the STATUS control to txtStatus. Then Me.
txtStatus.Undo should work for you.
 
UnDo *only* works on bound controls!
FYI: I am not sure if it makes any difference or not, the STATUS field it is
available as control in my form but it is not a field showing in my form.
I have a form which has a check box that will replace a comment in a field
called STATUS in my table. Before my form is opened, the STATUS field already
[quoted text clipped - 37 lines]
End If
End Sub
 
Hi Silvio,

First a couple of things.... Like RuralGuy said, "Status" is a reserved
word. For more info, see the following knowledge base articles for more
reserved words.
In addition to those listed in the article, avoid any word which is
also an access property, i.e. Height, Width, etc., even if not listed
in the articles.

For additional reserved words, see the Microsoft KnowledgeBase article
for your version of Access:

109312 'Reserved Words in Microsoft Access' for Access 97
209187 'ACC2000: Reserved Words in Microsoft Access'
286335 'ACC2002: Reserved Words in Microsoft Access'
321266 'ACC2002: Microsoft Jet 4.0 Reserved Words'


One way to avoid reserved words as object names is to use a naming convention.
Here are a couple of sites to read:

Commonly used naming conventions
http://www.mvps.org/access/general/gen0012.htm

LESZYNSKI (HUNGARIAN) NAMING CONVENTION
http://www.acc-technology.com/namconv.htm

Develop a Consistent Naming Convention for Your Database Objects
http://www.devx.com/dbzone/Article/10866/0/page/1

FYI: I am not sure if it makes any difference or not, the STATUS field it is
available as control in my form but it is not a field showing in my form.

For clarity, tables contain fields, forms contain objects that can be bound
(to a field in a table/query) or unbound (no recordsource). And you need to
be consistant. :)

Now to your problem.

When you execute the procedure "Private Sub ynFromZone_Click()" by setting
the checkbox to TRUE (has a check), you save the old value of "STATUS" in a
variable "OriginalValue". Then you update the control "STATUS".

The problem is that when the Procedure finishes executing, the variable
"OriginalValue" is destroyed. The value is gone.

One way to solve this is to put an unbound text box in the form header or
next to the text box "STATUS". Name it something like "utbOriginalValue" (u
= unbound,, tb = text box). Set the Visible property to FALSE.
The code will then save the old value to the text box on the form. The value
will be avaliable *until the form is closed*. BTW, this (probably) won't work
if the form is a continous form.


Change the code to:

(untested Air code)
Private Sub ynFromZone_Click()

'Me.utbOriginalValue is a control on the form
Me.utbOriginalValue = Me!Status

If Me!ynFromZone = True Then

'Time() is just the time
' Now() is the Date AND the Time
'it looks like you are using
'prefix "t" for Time and
'prefix "d" for Date
'so I changed Now to Time

Me!tFromZone = Time()
'Me!tFromZone = Now
Me!dFromZone = Date()
Me!Status = "Pending Assignment since " & Date()
Else
Me!Status = Me.utbOriginalValue
Me!tFromZone = Null
Me!dFromZone = Null
End If
Me.Refresh
End Sub



HTH
 
Back
Top