Subtracting two Times to fill out textbox?

t3nchi

Registered User.
Local time
Today, 05:13
Joined
Sep 28, 2005
Messages
79
I have 2 time boxes with times in them. How do I get the 3rd textbox to display the difference between those times?
 
Have you tried setting the ControlSource of TextBox3 to:
=TextBox2-TextBox1
 
RuralGuy said:
Have you tried setting the ControlSource of TextBox3 to:
=TextBox2-TextBox1

Doesn't seem like the field is being filled out. I changed it from text to number as well. Nothing.
 
Last edited:
How about posting *exactly* what you have as the ControlSource of TextBox3? If you used your control names it should have worked!
 
Hey you're right. So it calculates it but does it store it into the table?
 
Last edited:
Access has a nasty habit of naming controls the same name as the field to which it is bound. Guess what? This confuses Access later on when you get around to doing some coding. I change the control name to have a preface of the type of control, txtControl for TextBox, cboControl for a ComboBox, etc. Yes, the txtduration control should not be bound! It is a really bad practice to store calculated values in a table. Recalculate if you need the value again but do not store the answer! If you change the control names then the ControlSource of the txtDuration control will be:
=txtEndTime-txtStartTime or something like it. Using the default value will not work, as you discovered. Add the controls rather than the fields since the fields are not updated until you save the record.
 
RuralGuy said:
Access has a nasty habit of naming controls the same name as the field to which it is bound. Guess what? This confuses Access later on when you get around to doing some coding. I change the control name to have a preface of the type of control, txtControl for TextBox, cboControl for a ComboBox, etc. Yes, the txtduration control should not be bound! It is a really bad practice to store calculated values in a table. Recalculate if you need the value again but do not store the answer! If you change the control names then the ControlSource of the txtDuration control will be:
=txtEndTime-txtStartTime or something like it. Using the default value will not work, as you discovered. Add the controls rather than the fields since the fields are not updated until you save the record.

thanks RG.
 
You are more than welcome. I take it that solved your problem?
 
I noticed that when I enter:

start = 12:00 am
end = 1:00 am

the duration is calculated to be... 0.04166667.... how's that?
 
Hey thanks again RG, that's a really useful page for me.
 
You're welcome. The whole site is *loaded* with really good stuff!
 

Users who are viewing this thread

Back
Top Bottom