Insert Date and Time on click

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi

I have built a database to replace an old Job Clocking Card system in a
factory. When the user enters their job details and presses submit i would
like the Date and Time to be automatically placed into a table with fields i
have already defined and Data and Time.

Is this possible? Is so does anyone know the VBA/Marco for it or point me in
the right direction.

Would greatly appreicate it if anyone could help.

Kind Regards

Adam Gale
 
Use a Datetime data type field and set field default to =Now() so when the
record is created it will store the current date and time.
 
Hi dears,

But i have a comment here ( when i used the mentiond way I had found that
the current time is added to the next generated record and not to the current
editing record , how can i solve this problem?
 
Shaker,

Karl's suggestion of using the Default Value means the date/time will be
recorded at the time a new record is first created. Not at the time
when the record is completed. If this does not meet your requirements,
then another approach is needed. Such as a macro or VBA procedure on
the form's Before Update event. In this case, if a macro, you would use
the SetValue action, with these arguments:
Item: [NameOfYourDateTimeField]
Expression: Now()
 
Did you set the default in the table or the form?
If you set the default of the field in the table it should work correctly.
 
Dears
Pease come with me step by step
1- I created a new field in design view
2- I specified tow fields for entering data manually
3- I specified third field to show the date of entry, then i set its defualt
value to Now(),and then I saved the table, but when I reopend the table with
data sheet view, I saw specific value in the third column (date of entry)
with knowing that I didnt make any data entry in this table yet, and when i
tried to enter data in the first row the date of entry value remaine the same
but the updated one is shown in the next row, and this means that when I
start to enter data in the row 1 the curren date/time value appears in the
row 2 and when start enter data in the row 2 the current date/time value
appears in the row 3 and so on!!!!!!!!

--
Shaker Rayya
Syriatel CO
Credit Support Coordinator


Steve Schapel said:
Shaker,

Karl's suggestion of using the Default Value means the date/time will be
recorded at the time a new record is first created. Not at the time
when the record is completed. If this does not meet your requirements,
then another approach is needed. Such as a macro or VBA procedure on
the form's Before Update event. In this case, if a macro, you would use
the SetValue action, with these arguments:
Item: [NameOfYourDateTimeField]
Expression: Now()

--
Steve Schapel, Microsoft Access MVP

shaker said:
Hi dears,

But i have a comment here ( when i used the mentiond way I had found that
the current time is added to the next generated record and not to the current
editing record , how can i solve this problem?
 
Hi Steve

Thank you for your reply. I’ve only just realised that the time being set is
that of when the record is first created and not when it is submitted.

I have tried your method, but am encountering some trouble. The table the
field resides in is called Job and the field i would like to submit the time
to when submit button is selected is called Clocking Time.

Firstly i cannot find the action setValue action when building a Macro and
am not sure of the parameters. Also would it possible to create another Marco
outputting the date too to another field. If you could walk me through
creating a Macro i would be greatly appreciated.

Kind Regards

Adam

Steve Schapel said:
Shaker,

Karl's suggestion of using the Default Value means the date/time will be
recorded at the time a new record is first created. Not at the time
when the record is completed. If this does not meet your requirements,
then another approach is needed. Such as a macro or VBA procedure on
the form's Before Update event. In this case, if a macro, you would use
the SetValue action, with these arguments:
Item: [NameOfYourDateTimeField]
Expression: Now()

--
Steve Schapel, Microsoft Access MVP

shaker said:
Hi dears,

But i have a comment here ( when i used the mentiond way I had found that
the current time is added to the next generated record and not to the current
editing record , how can i solve this problem?
 
Adam,

Perhaps you are using Access 2007? If so, perhaps you need to click the
'Show All Actions' button in the Show/Hide group on the Macro Design
Tools tab, before the SetValue action will be available to you.

Generally, you can put the date and time both in the one field. Usually
there is no need to separate them into a date field and a time field,
which only achieves to add unnecessary complexity to your system.

Anyway, the functions relevant are:
Now() - the current date and time
Date() - the current date
Time() - the current time
:-)

When you create your macro, and enter the SetValue action into the macro
design window, then down the bottom you will see two boxes for the macro
Properties, being:
Item:
Expression:

So, in the Item property you enter the name of the field, enclosed in
[]s, so in your example:
[Clocking Time]
.... and in the Expression property you enter the expression that will
evaluate to the value you wnat to set the field to, so in your example:
Time()

The macro will be entered, via design view of your form, in the On Click
event property of the command button.
 
Thank you Steve, that was very helpful.

I now have it all sorted.

Kind Regards


Adam



Steve Schapel said:
Adam,

Perhaps you are using Access 2007? If so, perhaps you need to click the
'Show All Actions' button in the Show/Hide group on the Macro Design
Tools tab, before the SetValue action will be available to you.

Generally, you can put the date and time both in the one field. Usually
there is no need to separate them into a date field and a time field,
which only achieves to add unnecessary complexity to your system.

Anyway, the functions relevant are:
Now() - the current date and time
Date() - the current date
Time() - the current time
:-)

When you create your macro, and enter the SetValue action into the macro
design window, then down the bottom you will see two boxes for the macro
Properties, being:
Item:
Expression:

So, in the Item property you enter the name of the field, enclosed in
[]s, so in your example:
[Clocking Time]
.... and in the Expression property you enter the expression that will
evaluate to the value you wnat to set the field to, so in your example:
Time()

The macro will be entered, via design view of your form, in the On Click
event property of the command button.

--
Steve Schapel, Microsoft Access MVP
Hi Steve

Thank you for your reply. I’ve only just realised that the time being set is
that of when the record is first created and not when it is submitted.

I have tried your method, but am encountering some trouble. The table the
field resides in is called Job and the field i would like to submit the time
to when submit button is selected is called Clocking Time.

Firstly i cannot find the action setValue action when building a Macro and
am not sure of the parameters. Also would it possible to create another Marco
outputting the date too to another field. If you could walk me through
creating a Macro i would be greatly appreciated.
 
Back
Top