current date and time on save

eugz

Registered User.
Local time
Today, 17:23
Joined
Aug 31, 2004
Messages
128
Hi all.
In my form I have 2 textbox that display current date and time
Code:
Private Sub Form_Timer()
    txtDate1.Caption = Format(Now, "mmm d yyyy")
    txtTime1.Caption = Format(Now, "hh:mm AMPM")
End Sub
I would like when user close form by save evet values of current time and date save in Table1.
Can anyone please help me in this.
 
Create a field in your table and then just put

yourfieldname = now()

in the onclick event of your save button
 
Thanks for replay.
Yes that is right if need to display current date and time. I would like to do by this way, of cause if it posiable.
For instance, I saved record1 with date 5/26/09 and time 11:00 AM in Date and Time of Table1. Next time when I open record1 of Form1 fields txtDate and txtTime will have same data like was save in the Table1. But if user will open new record I would like that fields txtDate and txtTime will display current date and time.
Thanks for help.
 
So you want existing records to keep their original date and new records to take on now's date and time??
 
Yes. Existing records to keep original date and time. Next new records will store data depends on date and time when form will opened.
 
ok so the datefield will be blank when you open the form if it is new so do soemthing like
Code:
if isnull(yourdatefield) then 
yourdatefield = now() 
else
'dont do anything
end if

in the save event of the button
 
I find it better to use the Form's Before update event like this:


Code:
Private Sub Form_BeforeUpdate(Cancel As Integer)

If Me.NewRecord Then

   Me.YourConytrolName = Now()
   
End If


End Sub



What would be even easier is to set the Default value for the field in the table to be Now()
 

Users who are viewing this thread

Back
Top Bottom