|
 |
access thread: Updating Date Fields using VB
Message #1 by "Aaron Dennis" <aarondennis@s...> on Thu, 25 Apr 2002 09:57:56
|
|
Hello,
I am having dificulty updating some date fields in a form that I have
designed.
I have four date fields, one of the date fields will allow a user to input
a date, lets call this field SOURCE, the other three date fields are equal
to SOURCE plus a certain period of time, lets call these fields
DESTINATION 1,2 and 3. For example I input the date 01/01/01 in the source
field then immediatly DESTINATION 1 will be eqaul to 01/01/02.
The code I have written in the After_Update section of the SOURCE field
is:
Me!DESTINATION_1 = SOURCE + 365
Now, going back to the normal form view I should be able to input a date
in the SOURCE field and when I press TAB the DESTINATION_1 field should
get updated immediatly. This is not the case, it gets updated when I go
back to the previous record or go out of the form, then go back to the
record.
I just want to insert the date in the SOURCE field and have values
inserted in to the DESTINATION fields when i press tab.
Can anyone help me please?
Kind Regards,
Message #2 by "Foote, Chris" <Chris.Foote@u...> on Thu, 25 Apr 2002 10:36:50 +0100
|
|
Hi Aaron!
I'm not an expert in these things, but, as I understand it, the data you are
creating (DESTINATION 1) is not written to the underlying table (or query)
_until_ you move out of the current (dirty) record.
I think one way round this is to use an unbound control (text box) for
DESTINATION 1 and write it's data to your table when you move to a different
record (or indeed close the form).
There is a "Requery" action that may be worth investigating but I've no
experience with this.
Do let the list know how you get on!
Regards!
Spike
> -----Original Message-----
> From: Aaron Dennis [mailto:aarondennis@s...]
> Sent: Thursday, April 25, 2002 10:58 AM
> To: Access
> Subject: [access] Updating Date Fields using VB
>
>
> Hello,
>
> I am having dificulty updating some date fields in a form that I have
> designed.
>
> I have four date fields, one of the date fields will allow a
> user to input
> a date, lets call this field SOURCE, the other three date
> fields are equal
> to SOURCE plus a certain period of time, lets call these fields
> DESTINATION 1,2 and 3. For example I input the date 01/01/01
> in the source
> field then immediatly DESTINATION 1 will be eqaul to 01/01/02.
>
> The code I have written in the After_Update section of the
> SOURCE field
> is:
>
> Me!DESTINATION_1 = SOURCE + 365
>
> Now, going back to the normal form view I should be able to
> input a date
> in the SOURCE field and when I press TAB the DESTINATION_1
> field should
> get updated immediatly. This is not the case, it gets updated
> when I go
> back to the previous record or go out of the form, then go
> back to the
> record.
>
> I just want to insert the date in the SOURCE field and have values
> inserted in to the DESTINATION fields when i press tab.
>
> Can anyone help me please?
>
> Kind Regards,
Message #3 by "Gregory Serrano" <SerranoG@m...> on Thu, 25 Apr 2002 13:42:35
|
|
Aaron,
<< The code I have written in the After_Update section of the SOURCE field
is:
Me!DESTINATION_1 = SOURCE + 365 >>
Try putting this in the source's "After Update" event:
Me.Destination1 = DateAdd("YYYY", 1, Me.Source)
The first argument changes depending on the time interval, e.g. "YYYY" for
year and "M" for month, etc. The second argument is the amount of time
you want to pass, in this case one year. If the string were "M" then
you'd be adding one month. The third argument is the date you want to add
the time to. See help for the function DateAdd.
Greg
|
|
 |