PC Review


Reply
Thread Tools Rate Thread

Create a Cmd Button to copy time

 
 
bumper338
Guest
Posts: n/a
 
      9th Feb 2009
Good day all,

I am not sure if I should post this question here or not. What I would like
to know is how would I create a command button to copy the current time value
into a table. For example, you click on the button and it records the time
the entry was made automatically.

Any other suggestion would be great.

Thanks,
 
Reply With Quote
 
 
 
 
Dirk Goldgar
Guest
Posts: n/a
 
      9th Feb 2009
"bumper338" <(E-Mail Removed)> wrote in message
news:129F3E5C-C0E8-4DCE-A1CB-(E-Mail Removed)...
> Good day all,
>
> I am not sure if I should post this question here or not. What I would
> like
> to know is how would I create a command button to copy the current time
> value
> into a table. For example, you click on the button and it records the
> time
> the entry was made automatically.



It's not clear to me whether you want to add a new record to this table or
update an existing one. And it could also be that you just want to insert
the time into a field in the current record on a form. I don't know which
of these you want to do, if any, so I'll give you examples for all three:

'----- start of code to insert record in table -----
Private Sub cmdInsertTime_Click()

CurrentDb.Execute _
"INSERT INTO YourTable (YourTimeField) Values(Now())", _
dbFailOnError

End Sub
'----- end of code to insert record in table -----


'----- start of code to update record in table -----
Private Sub cmdUpdateTime_Click()

CurrentDb.Execute _
"UPDATE YourTable " & _
"SET YourTimeField = Now() " & _
"WHERE YourIDField = " & YourIDValue, _
dbFailOnError

End Sub
'----- end of code to update record in table -----


'----- start of code to update a field in the form's current record -----
Private Sub cmdUpdateTimeOnForm_Click()

Me!YourTimeField = Now()

End Sub
'----- end of code to update a field in the form's current record -----


NOTE: all of the above examples use the Now() function, which returns the
current date *and* time. If you want the time alone (which is actually
returned as the time on "date 0" -- December 30, 1899), you can use the
Time() function instead of the Now() function.

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

(please reply to the newsgroup)

 
Reply With Quote
 
dymondjack
Guest
Posts: n/a
 
      9th Feb 2009
If you are trying to track the time a record was modified, this can be done
without using a button.

In the table, add a date field (something like ModifiedDate). If your form
is a bound form, you can use the following code in the BeforeUpdate event of
the form:

Me.[ModifiedDate] = Now()

This will save the last modified date/time every time the record is updated.

--
Jack Leach
www.tristatemachine.com

- "First, get your information. Then, you can distort it at your leisure."
- Mark Twain


"bumper338" wrote:

> Good day all,
>
> I am not sure if I should post this question here or not. What I would like
> to know is how would I create a command button to copy the current time value
> into a table. For example, you click on the button and it records the time
> the entry was made automatically.
>
> Any other suggestion would be great.
>
> Thanks,

 
Reply With Quote
 
fredg
Guest
Posts: n/a
 
      9th Feb 2009
On Mon, 9 Feb 2009 08:22:02 -0800, bumper338 wrote:

> Good day all,
>
> I am not sure if I should post this question here or not. What I would like
> to know is how would I create a command button to copy the current time value
> into a table. For example, you click on the button and it records the time
> the entry was made automatically.
>
> Any other suggestion would be great.
>
> Thanks,



Add a DateTime datatype field to the table that the form is bound to.
Add this field to the form.

Do you wish to change the time every time the button is clicked, even
on existing records?
Code the command button click event:
To add the date as well as the time:
Me![FieldName] = Now()

To add just the time:
Me![FieldName] = Time()

Why do you think you need a button to do this.
Why not simple place the code in the Form's AfterUpdate event so that
it records the time without user intervention each time a record is
saved.

Note: To save the time only when a NEW record is created, use:
If Me.NewRecord Then
Me![FieldName] = Now()
End If
--
Fred
Please respond only to this newsgroup.
I do not reply to personal e-mail
 
Reply With Quote
 
bumper338
Guest
Posts: n/a
 
      10th Feb 2009
Thanks everyone, I will look at these examples and see what will work best.

Thanks again.



"bumper338" wrote:

> Good day all,
>
> I am not sure if I should post this question here or not. What I would like
> to know is how would I create a command button to copy the current time value
> into a table. For example, you click on the button and it records the time
> the entry was made automatically.
>
> Any other suggestion would be great.
>
> 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
VBA to create button on sheet after copy and to change the caption ArielZusya Microsoft Excel Programming 7 16th Jan 2008 09:59 PM
trying to create a copy button?? =?Utf-8?B?bGVtbWVpbg==?= Microsoft Access Forms 1 22nd Apr 2007 03:02 PM
How to create command button to save the dates and time =?Utf-8?B?S2VuIFZv?= Microsoft Excel Misc 6 5th Jan 2006 04:18 AM
IS IT POSSIBLE TO CREATE A COMMAND BUTTON TO MAKE TIME STAMPS =?Utf-8?B?QkNFTlRFTk8=?= Microsoft Word Document Management 2 18th Oct 2005 06:22 AM
How to programatically create/copy a button? Matt Microsoft Access VBA Modules 1 30th Jul 2003 08:12 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 06:36 AM.