Wrox Programmer Forums
|
Access VBA Discuss using VBA for Access programming.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Access VBA section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old December 24th, 2003, 12:36 PM
bph bph is offline
Friend of Wrox
 
Join Date: Dec 2003
Posts: 102
Thanks: 2
Thanked 0 Times in 0 Posts
Default event coding - Access VBA

I have a single table MSAccess database with one form, which the user enters data about each client. I have a field called date_last_updated which has datatype general date.

When the user clicks AddRecord command button, I want the current date\time [now()] entered into this field.

Also if the user updates an existing record and clicks the saverecord button, I want the field [date_last_updated] to update to the current date\time.

Not so good with this stuff yet. Thx, bph

 
Old December 24th, 2003, 01:53 PM
sal sal is offline
Friend of Wrox
 
Join Date: Oct 2003
Posts: 702
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Set the fields default value to Now().
Create a different field for keeping when the record was entered an another for when the record was changed. To make sure that the date_last_updated field gets a value every time is changed use ado and set the value for the field to Now().



Sal
 
Old December 24th, 2003, 01:57 PM
bph bph is offline
Friend of Wrox
 
Join Date: Dec 2003
Posts: 102
Thanks: 2
Thanked 0 Times in 0 Posts
Default

Thanks! I'll look up the ado stuff and figure that out.

 
Old December 27th, 2003, 05:44 PM
Authorized User
 
Join Date: Oct 2003
Posts: 53
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi BPH,
You can also, on the BeforeUpdate event of the Form, you can put...

Private Sub Form_BeforeUpdate(Cancel As Integer)
Me.Date_Last_Updated.Value = Now
End Sub

Or, If you made the command buttons yourself...

Private Sub cmdAddRecord_AfterUpdate()
Me.Date_Updated.Value = Now
End Sub

Hope this helps, good luck!

 
Old December 27th, 2003, 06:55 PM
sal sal is offline
Friend of Wrox
 
Join Date: Oct 2003
Posts: 702
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Now, that is even easier. I learn something new every day.



Sal
 
Old January 6th, 2004, 12:17 PM
bph bph is offline
Friend of Wrox
 
Join Date: Dec 2003
Posts: 102
Thanks: 2
Thanked 0 Times in 0 Posts
Default

[quote]Originally posted by DBoulos
 Hi BPH,
You can also, on the BeforeUpdate event of the Form, you can put...

Private Sub Form_BeforeUpdate(Cancel As Integer)
Me.Date_Last_Updated.Value = Now
End Sub

Or, If you made the command buttons yourself...

Private Sub cmdAddRecord_AfterUpdate()
Me.Date_Updated.Value = Now
End Sub

Hope this helps, good luck!


[/Thanks]:)






Similar Threads
Thread Thread Starter Forum Replies Last Post
Organization chart in Excel through VBA coding mangesh.gohad Excel VBA 0 July 26th, 2008 12:23 PM
Code works in Excel VBA but not Access VBA fossx Access VBA 2 May 21st, 2007 08:00 AM
What does (Me!) and (Dim)stand for in VBA Coding? srswedeen Access VBA 1 October 14th, 2005 06:41 AM
KeyPress Event in VB different from VBA PaulG Beginning VB 6 3 February 3rd, 2004 01:31 PM
Click Event for VBA listbox Blade Beginning VB 6 1 June 11th, 2003 09:17 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.