Calculate without command button?

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

Guest

Hello,

Currently, I have a "Date In" and "Date Out" field on my form. When
information is inputted, I hit a command button and in another field
"Turnaround Time" it calculates the difference. Is there a way for the
Turnaround Time field to calculate without using the "Calculate" command
button?

My reason is because I have the form protected from editing once a record is
completed so it is read only unless a password is entered to unlock the
fields. However, if the "Calculate" button is clicked the record is no
editable. Everything works fine on my form except this one issue. If anyone
can please help or make a suggestion, I would greatly appreciate it. Also,
please simplify answers so it will be easier for me to follow.

Thanks!!!
 
1) you could disable the calculate button at the same time that you
make the other fields not editable.

However, you do not need the button in the first place.

in the afterupdate for BOTH the datein and the dateout fields

if not isnull(me.datein) and not isnull(me.dateout) then
me.turnaroundtime = ........... calculations
endif

Some "Normalizers" would suggest that you don't even store the
turnaround time. That is your call and depends on the degree of
complexity of the calculations since you would have to duplicate the
calculations whenever you needed to use/display the field.

Ron
 
The following advice is something you should really think about when
deciding to keep or drop the "turnaround time". It is good advise, and
I was not trying to make fun of this in the prior post. But it is
something you should think about. (Along with the price change
possibility as one reason to store it, is the potential of the
calculation method to change ie. a customer rate code change or some
other item that can change over time. Or just the probability of the
calculation method changing.)

Ron

Here are the comments: ........................

In a database, it is almost always a bad idea to store data which is
derived/calculated from other existing data. It adds additional
unnecessary complication and difficulty, and increased probability of
error, in the sense that any time data is entered or changed it needs
to
be updated in more then one place. This is based on one aspect of the
principle of data normalisation - one place for each data element, and
each data element in its place. Generally, if it can be
calculated/derived, then calculate/derive it when you need it.


There are very specific examples of where this is not the case... this
is where the values that the calculation is based on can change over
time. The classic example of this is an Invoice Amount based on a
Quantity * UnitPrice calculation, which needs to be stored to reflect
the price at the time of purchase, otherwise it will be wrong if the
price subsequently changes. But these circumstances are rare - and
even
then some "purists" would argue that you should use a price history
table, and still perform the calculation on the fly based on a lookup
to
the price for the purchase date.


In the case of Damo Waterboy's question, in fact this is not even a
calculation, as the desired result can be obtained simply by a
formatting of the existing data. So that would mean he would have two
fields with exactly the same information in them, which is clearly
pointless.
 
Hi Ron,

It doesn't work. If I put the code in both fields after up date, it give me
an error and if I put it in one it doesn't do anything at all. After the =
you have ..........calculations. What am I suppose to put there if anything?

Thanks!!
 
Whatever calculations are right now in the onclick event of the
calculate button are what you would put in the code I supplied. In
fact, you could simply call the calculatebutton subroutine. in the
code.

if not isnull(me.datein) and not isnull(me.dateout) then
caluclatebuttonname_Click
endif

To disable the button you would code

me.calculatebuttoname.enable = False


Ron
 
Whatever calculations are right now in the onclick event of the
calculate button are what you would put in the code I supplied. In
fact, you could simply call the calculatebutton subroutine. in the
code.

if not isnull(me.datein) and not isnull(me.dateout) then
caluclatebuttonname_Click
endif

To disable the button you would code

me.calculatebuttoname.enable = False


Ron
 

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

Back
Top