PC Review


Reply
Thread Tools Rate Thread

Date/Time Now () not working the way I want it to

 
 
=?Utf-8?B?Y2VuZ2VsMDMyNw==?=
Guest
Posts: n/a
 
      10th Nov 2006
Within my Form I have a subform in datasheet view that only has two fields
Date/Time and Comments/Status. I'd like to auto insert the current date &
time in the sub-form when someones adds an entry to the comments/status
field.

I've set the default value to now() in the sub-form (design view), however,
it automatically inserts the date and time for the next row instead of
keeping with the row where I type in new data.

Please help. Thanks.

 
Reply With Quote
 
 
 
 
Dirk Goldgar
Guest
Posts: n/a
 
      10th Nov 2006
"cengel0327" <(E-Mail Removed)> wrote in message
news:A1737ED9-5A9F-416D-8269-(E-Mail Removed)
> Within my Form I have a subform in datasheet view that only has two
> fields Date/Time and Comments/Status. I'd like to auto insert the
> current date & time in the sub-form when someones adds an entry to
> the comments/status field.
>
> I've set the default value to now() in the sub-form (design view),
> however, it automatically inserts the date and time for the next row
> instead of keeping with the row where I type in new data.
>
> Please help. Thanks.


So the user is editing an existing record, and you want to save the
date/time of that edit in the [Date/Time] field of that record? For
that, you'll have to use the form's BeforeUpdate event. An event
procedure might look like this:

'----- start of example code -----
Private Sub Form_BeforeUpdate(Cancel As Integer)

Me![Date/Time] = Now()

End Sub
'----- end of example code -----

You should be aware that field names containing the "/" character are
not a very good idea, as they force you to enclose the field name in
brackets ([]) every time you use it.

--
Dirk Goldgar, MS Access MVP
www.datagnostics.com

(please reply to the newsgroup)


 
Reply With Quote
 
=?Utf-8?B?S2VuIFNoZXJpZGFu?=
Guest
Posts: n/a
 
      10th Nov 2006
Instead of using the DefaultValue property put code along these lines in the
subform's BeforeInsert event procedure:

Me.[Date/Time] = Now()

The current date/time value will be inserted into the field as soon as the
user begins to add data to a new record. If you set the date/time control's
locked property to True (Yes) and its Enabled property to False (No) the
field will look as normal but the user won't be able to change the value
inserted. In fact they won't even be able to move focus to the field.

Ken Sheridan
Stafford, England

"cengel0327" wrote:

> Within my Form I have a subform in datasheet view that only has two fields
> Date/Time and Comments/Status. I'd like to auto insert the current date &
> time in the sub-form when someones adds an entry to the comments/status
> field.
>
> I've set the default value to now() in the sub-form (design view), however,
> it automatically inserts the date and time for the next row instead of
> keeping with the row where I type in new data.
>
> Please help. Thanks.
>


 
Reply With Quote
 
=?Utf-8?B?Y2VuZ2VsMDMyNw==?=
Guest
Posts: n/a
 
      10th Nov 2006
That was exactly what I needed - thank you! Thanks for the tip on removing
the / - I will do that.



"Dirk Goldgar" wrote:

> "cengel0327" <(E-Mail Removed)> wrote in message
> news:A1737ED9-5A9F-416D-8269-(E-Mail Removed)
> > Within my Form I have a subform in datasheet view that only has two
> > fields Date/Time and Comments/Status. I'd like to auto insert the
> > current date & time in the sub-form when someones adds an entry to
> > the comments/status field.
> >
> > I've set the default value to now() in the sub-form (design view),
> > however, it automatically inserts the date and time for the next row
> > instead of keeping with the row where I type in new data.
> >
> > Please help. Thanks.

>
> So the user is editing an existing record, and you want to save the
> date/time of that edit in the [Date/Time] field of that record? For
> that, you'll have to use the form's BeforeUpdate event. An event
> procedure might look like this:
>
> '----- start of example code -----
> Private Sub Form_BeforeUpdate(Cancel As Integer)
>
> Me![Date/Time] = Now()
>
> End Sub
> '----- end of example code -----
>
> You should be aware that field names containing the "/" character are
> not a very good idea, as they force you to enclose the field name in
> brackets ([]) every time you use it.
>
> --
> Dirk Goldgar, MS Access MVP
> www.datagnostics.com
>
> (please reply to the newsgroup)
>
>
>

 
Reply With Quote
 
Pablito
Guest
Posts: n/a
 
      19th Jun 2009
Hi Ken,

I've been searching all the related posts for Date/Time functions in a form
and your example below was just what I was looking for. It works GREAT!!

Thanks!!
Paul

"Ken Sheridan" wrote:

> Instead of using the DefaultValue property put code along these lines in the
> subform's BeforeInsert event procedure:
>
> Me.[Date/Time] = Now()
>
> The current date/time value will be inserted into the field as soon as the
> user begins to add data to a new record. If you set the date/time control's
> locked property to True (Yes) and its Enabled property to False (No) the
> field will look as normal but the user won't be able to change the value
> inserted. In fact they won't even be able to move focus to the field.
>
> Ken Sheridan
> Stafford, England
>
> "cengel0327" wrote:
>
> > Within my Form I have a subform in datasheet view that only has two fields
> > Date/Time and Comments/Status. I'd like to auto insert the current date &
> > time in the sub-form when someones adds an entry to the comments/status
> > field.
> >
> > I've set the default value to now() in the sub-form (design view), however,
> > it automatically inserts the date and time for the next row instead of
> > keeping with the row where I type in new data.
> >
> > Please help. Thanks.
> >

>

 
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
Working with Date/Time Thanks Microsoft Excel Worksheet Functions 1 14th Jul 2009 03:37 PM
working with time date in a query Bruce Microsoft Access Queries 4 5th Jun 2008 01:18 PM
Date - Date, TimeStamp - Time, Joined, BUT NOT WORKING =?Utf-8?B?UmljaGFyZA==?= Microsoft Access Queries 0 22nd Jun 2005 01:33 PM
date and time not working =?Utf-8?B?QUNF?= Windows XP Help 1 20th Apr 2004 01:40 AM
Working w/ Date and Time in SUMIF carl Microsoft Excel Worksheet Functions 1 5th Mar 2004 01:45 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 12:46 AM.