By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,963 Members | 924 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,963 IT Pros & Developers. It's quick & easy.

Set variable

P: n/a
Hi
I want to be able to set a variable on the 'on got focus' event and use
that value in the 'on lost focus' event. This is because the on click event
enters a date into a field and I want to record what the old date was.
Is this possible or do I have to think along the lines of populating a
field in a temp table? I have to repeat this for other button objects on the
form.

Thanks in advance
Dave
Nov 13 '05 #1
Share this Question
Share on Google+
5 Replies


P: n/a
rkc
David wrote:
I want to be able to set a variable on the 'on got focus' event and use
that value in the 'on lost focus' event. This is because the on click event
enters a date into a field and I want to record what the old date was.
Is this possible or do I have to think along the lines of populating a
field in a temp table? I have to repeat this for other button objects on the
form.


Yes you can do it. OnFocus fires before OnClick.
You can also use On MouseDown.
Nov 13 '05 #2

P: n/a
One assumes there is some code which "enters a date into a field". In
the procedure where this code lives one could declare a static variable
and assign the old value of the textbox? to it just before the new date
is entered into the field.
You also may be able to use the OldValue of the control. I prefer my
own coding for this as I find that Access may be erratic about updating
OldValue (or perhaps I am just too lazy to learn when and how it is
updated).

Nov 13 '05 #3

P: n/a
I have tried setting a variable but utdoesnt seem to work, do u have the
code required to make it work?

thanks
Dave
"rkc" <rk*@rochester.yabba.dabba.do.rr.bomb> wrote in message
news:fB******************@twister.nyroc.rr.com...
David wrote:
I want to be able to set a variable on the 'on got focus' event and
use that value in the 'on lost focus' event. This is because the on click
event enters a date into a field and I want to record what the old date
was.
Is this possible or do I have to think along the lines of populating
a field in a temp table? I have to repeat this for other button objects
on the form.


Yes you can do it. OnFocus fires before OnClick.
You can also use On MouseDown.

Nov 13 '05 #4

P: n/a
rkc
David wrote:
I have tried setting a variable but utdoesnt seem to work, do u have the
code required to make it work?


As Mr. Fairfield pointed out, the most logical place to save the old
value is in the same code block that changes it in the first place.

The option's for where you save it are endless. If you're going to
use the value in the same form it's saved in you can use a form level
variable. That is a variable declared at the beginning of the form's
module outside any methods there may be.

Multiple values can be stored in a form level collection using the
control name as the key.
Nov 13 '05 #5

P: n/a
David wrote:
Hi
I want to be able to set a variable on the 'on got focus' event and use
that value in the 'on lost focus' event. This is because the on click event
enters a date into a field and I want to record what the old date was.
Is this possible or do I have to think along the lines of populating a
field in a temp table? I have to repeat this for other button objects on the
form.

Thanks in advance
Dave

As Lyle said, you can get the OldValue ex: Me.Text0.OldValue
If Me.Text0 <> Me.Text0.OldValue
I think this only works with bound variables.

You can also enter something at the top of the form's code module to
declare the value. The form module may look something like this

Option Compare Database
Option Explicit
Dim varStorageVariable 'declares the variable globally for the form

Sub A
varStorageVariable = "David"
msgbox varStorageVariable
End Sub
Sub B
varStorageVariable = "Roebuck"
msgbox varStorageVariable
End Sub
Sub C
A 'call the routine
B 'call the routine
End Sub

Nov 13 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.