PC Review


Reply
Thread Tools Rate Thread

Calculate based on two date fields, populate third which writed to

 
 
AndyG
Guest
Posts: n/a
 
      28th Aug 2008
MSAccess03. Scenerio: three text boxes (In; Out; Diff of type date.
User inputs date into 'In', moves to 'Out' and inputs date. I would like the
difference in the dates to do two things 1) populate box 3 'Diff', and also
2) to have the value in the box be written to the db.

I know I can do: DateDiff("d",In,Out) to get the difference,
however, what would the code look like to populate that box?
Would it be on 'Lost Focus' of the Out box? and what I really don't
understand is, even if I somehow put the value of the formula into
the third box, how does that get written to the db if the third box is
using a formula (unbound?)???

Help is greatly appreciated.
 
Reply With Quote
 
 
 
 
Jim Burke in Novi
Guest
Posts: n/a
 
      28th Aug 2008
Realistically you need some way of knowing that both dates have been entered
and are the correct dates. It's possible that the user could accidentally put
in a wrong date, then go back and change it. So you can't just assume that as
soon as both dates have been entered that it's safe to write the new value.
You may want a button they click that says the dates are entered and are
correct, then have the button click event write the DateDiff("d",In,Out)
value to your table. I don't know if you have a bound form, or if you're
opening a recordset to write to a table or what, not really sure exactly what
this part of your app is doing, so I'm not sure what to tell you on exactly
how to get that value into the field.

"AndyG" wrote:

> MSAccess03. Scenerio: three text boxes (In; Out; Diff of type date.
> User inputs date into 'In', moves to 'Out' and inputs date. I would like the
> difference in the dates to do two things 1) populate box 3 'Diff', and also
> 2) to have the value in the box be written to the db.
>
> I know I can do: DateDiff("d",In,Out) to get the difference,
> however, what would the code look like to populate that box?
> Would it be on 'Lost Focus' of the Out box? and what I really don't
> understand is, even if I somehow put the value of the formula into
> the third box, how does that get written to the db if the third box is
> using a formula (unbound?)???
>
> Help is greatly appreciated.

 
Reply With Quote
 
Klatuu
Guest
Posts: n/a
 
      29th Aug 2008
It is incorrect to store calculated data. It should be calculated when you
need to present it to the user either on a form, in a report, or when
exported.

The proper technique would be to use the control source of the third text
box to display the difference using the DateDiff function.

=DateDiff("d", Me.In, Me.Out)

If either of the dates have not been entered, the results will be Null, so
nothing will show in the text box until both dates are entered.
--
Dave Hargis, Microsoft Access MVP


"AndyG" wrote:

> MSAccess03. Scenerio: three text boxes (In; Out; Diff of type date.
> User inputs date into 'In', moves to 'Out' and inputs date. I would like the
> difference in the dates to do two things 1) populate box 3 'Diff', and also
> 2) to have the value in the box be written to the db.
>
> I know I can do: DateDiff("d",In,Out) to get the difference,
> however, what would the code look like to populate that box?
> Would it be on 'Lost Focus' of the Out box? and what I really don't
> understand is, even if I somehow put the value of the formula into
> the third box, how does that get written to the db if the third box is
> using a formula (unbound?)???
>
> Help is greatly appreciated.

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Auto-populate date field based on two other fields. Dee Microsoft Access 7 17th Feb 2010 07:23 PM
Populate value in form based on other fields Marcie Microsoft Access Form Coding 3 2nd Mar 2009 10:24 PM
How do I populate current date based on another fields output? Selli Microsoft Access VBA Modules 1 22nd Jul 2008 04:19 AM
Populate one field based on another fields value =?Utf-8?B?QWxhbg==?= Microsoft Access Form Coding 2 17th Aug 2006 06:00 PM
Populate fields based on a selection =?Utf-8?B?RGFsZQ==?= Microsoft Access Forms 0 13th Jul 2006 06:54 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 02:07 PM.