How JustAnswer Works:

  • Ask an Expert
    Experts are full of valuable knowledge and are ready to help with any question. Credentials confirmed by a Fortune 500 verification firm.
  • Get a Professional Answer
    Via email, text message, or notification as you wait on our site.
    Ask follow up questions if you need to.
  • 100% Satisfaction Guarantee
    Rate the answer you receive.

Ask Richard Your Own Question

Richard
Richard, Software Specialist
Category: Microsoft Office
Satisfied Customers: 32073
Experience:  Over 15 year experience resolving Microsoft Office Issues
32989067
Type Your Microsoft Office Question Here...
Richard is online now
A new question is answered every 9 seconds

Hi experts, Have a simple problem that I lack the knowledge

Resolved Question:

Hi experts,

Have a simple problem that I lack the knowledge to complete.
I am trying to code a form to record current time in a field when a button is pressed on the form.

i.e. I have a vehicle dispatched time field, and I want the database to record the time when the button is pressed,

Any assistance very welcome,

Thanks,

Bryan. [email protected]
Submitted: 4 years ago.
Category: Microsoft Office
Expert:  Richard replied 4 years ago.

Professional Help :

Hi there

Professional Help :

if it is sql or access, just put in as the default value

Professional Help :

=now()

Professional Help :

that will do it

Professional Help :

if you have difficulties, please let me know

Customer:

Thanks,

Professional Help :

your welcome, if it worked please remember to click accept

Customer:

So let me explain, I have a form which captures EMS vehicle dispatch data, the field I am trying to populate with the time is Call Details.Vehicle1 dispatch time, I am trying to get the time into that field on click from a button on the form, however, =now() doesnt work as it is formatted for time, not long date.

Customer:

Also am unsure of the query builder syntax to tell it to populate the other field with the time, once clicked

Professional Help :

what is it? MS SQL, ACCESS? .NET?

Professional Help :

once i know I can give you the correct syntax

Customer:

Access 2010

Professional Help :

ok, go to the field in form design

Professional Help :

right click and choose properties

Customer:

There

Professional Help :

ok look for default value

Professional Help :

in it type

Professional Help :

=now()

Professional Help :

and click out of it and test

Customer:

Ok, thanks, XXXXX XXXXX but remember, I need them to click a button to set the time, got pretty serious legal requirement as it is the recorded time for ambulance dispatch, there will be a lag between them starting capturing call data, and dispatching the ambulance, hence the requirement to trigger an event based on button click

Professional Help :

ok, then on the button event do this

Professional Help :

pretend the name of the field that holds the date it DATEFIELD

Professional Help :

then

Professional Help :

the onclick event of the button has this

Professional Help :

me.DATEFIELD.value = now()

Professional Help :

then when they click the button it would put it in the field

Customer:

Awesome, checking, thanks

Customer:

Do i need the table name or just the field name?

Professional Help :

just firld

Professional Help :

sorry not field

Professional Help :

control

Professional Help :

the name of the text box on your form that will hold the value

Customer:

Ok, sorry for being dumb, been years since I did this. Text box control is Vehicle 1 dispatch time, get an error when I enter me.Vehicle 1 dispatch time.value = now()

Professional Help :

no spaces

Customer:

Ah! do I need to rename the field in the table to kill out the spaces first?

Professional Help :

no, just name the control without spaces

Customer:

Ok, error now is it cant find macro called ME

Professional Help :

?

Professional Help :

did you do

Professional Help :

me.control.value = now()

Professional Help :

in the onclick event of the button?

Customer:

Yep,

Professional Help :

can you copy and paste it all here, including the sub name

Customer:

Exact text in the onclick event is: "me.Vehicle1dispatchtime.value = now()

Professional Help :

when you type me.

Professional Help :

do you see a list of controls?

Customer:

Starting over, 1 sec

Professional Help :

no problem

Customer:

Ok, when I do it in the expression builder I see it breakdown the command correctly, but now has different error.

Professional Help :

are you doing this in the onclick event of the button?

Professional Help :

let me make an example for you and send it

Customer:

Ok, thanks. I've done it both in the onclick box and also in the event builder, same result, I know Im being stupid, just cant remember how to!

Professional Help :

download this

Professional Help :

http://wikisend.com/download/128602/Database8.accdb

Professional Help :

look at form1

Professional Help :

and youll see how I have done it

Professional Help :

let me know if it still doesnt work for you please

Customer:

Thanks will check now

Customer:

I will do, Thanks for your help

Customer:

Got compile error: Method or data member not found.

Customer:

Am gonna take the spaces out of the field name and see if that works

Professional Help :

ok... but should matter

Professional Help :

just the control name is important

Customer:

OK, still no luck, matches your's exactly, with control name set right, Compile error: Method or data member not found

Professional Help :

can you upload the DB?

Professional Help :

go to www.wikisend.com

Professional Help :

give me the download link and I will do it for you

Professional Help :

how did you go with this Bryan?

Customer:

Uploaded database to link here: http://wikisend.com/download/408932/Emer-G-Med Project.accdb Table being populated is Call Details, Form in question is also Call details. You will see an unmarked button on top of the Time1 field (renamed to rule out a syntax error) if you could be so kind as to show me how you would populate the Time1 field on click I'd be very grateful

Professional Help :

ok, found the problem, you had the wrong name

Professional Help :

put this in the buttons onclick and replace the other code you did

Professional Help :

Me.Vehicle_1_dispatch_time.Value = Now()

Professional Help :

that works

Professional Help :

let me know how it goes please

Customer:

Brilliant, thanks a lot!!

Richard and 2 other Microsoft Office Specialists are ready to help you