Results 1 to 6 of 6
  1. #1
    DonBobCliff is offline Novice
    Windows 8 Access 2000
    Join Date
    May 2014
    Location
    Vermillion, SD
    Posts
    3

    Form Button To Upate a Form Field to "Now()"


    I am creating a table to capture specific actions and log the exact time said action occurs. I have built a table to include the Test name (Water Boil), and 4 subsequent fields for each action time (Pot on Stove, Burner Turned On, Temp Reached 150 Degrees, and Water Boiling). From this table, I've created a form to input the information for each record, and I want to create a button (or buttons) to input the "Now()" information to the specific field. Whether it's one button that inputs "Now()" to the current field, or it's a button to update each field makes no diff to me. Can anyone help this "Less than Moderate" User? Thanks in advance!

  2. #2
    burrina's Avatar
    burrina is offline VIP
    Windows 8 Access 2010 32bit
    Join Date
    Oct 2012
    Location
    Freeport,Texas
    Posts
    1,383
    Here is an example;

    Me.SomeField = Now()
    HTH

  3. #3
    DonBobCliff is offline Novice
    Windows 8 Access 2000
    Join Date
    May 2014
    Location
    Vermillion, SD
    Posts
    3
    Well, that seems simple. So what do I do with this? Put it in a macro, then tell the button to run the macro? If so, what command do I use in the macro to make it work? (Sorry, I understand how powerful Access is, but just don't know how to get it to do what I want.) Thanks!

  4. #4
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 7 64bit Access 2010 32bit
    Join Date
    Aug 2013
    Posts
    7,862
    You can create an event handler using the VBA editor. This will create a sub procedure that will trigger VBA to handle an event. You have to choose an event to fire the code first. Once you identify an event or events to trigger some code, you can click the ellipses(...) to the right of the event description and then select "Code Builder" to launch the VBA editor. Available events are listed in the property sheet under the "Events" tab. You can view the property sheet while in Design View of your form.

    So if you have a Command Button, you can fire code by creating a sub procedure for its On Click Event. You can use VBA to change the properties, among other things, of other controls. You only need to know the name of the control you want to effect. So for a control named "BoilTime", you could use the following VBA in a Click Event handler.

    Me.BoilTime.Value = Now()

    This uses the Now() function to retrieve the current system date and time and assign the value to the .Value property of the named control.

  5. #5
    Missinglinq's Avatar
    Missinglinq is offline VIP
    Windows 7 64bit Access 2007
    Join Date
    May 2012
    Location
    Richmond (Virginia, not North Yorkshire!)
    Posts
    3,018
    I can think of two ways to do this without having to have a separate Command Button for each of your DateTime Fields. The first would be to use the DoubleClick event for each of the Textboxes, like this:

    Code:
    Private Sub BoilTime_DblClick(Cancel As Integer)
     Me.BoilTime.Value = Now()
    End Sub

    You DoubleClick on the, in this case, BoilTime Textbox and the DateTime is filled in. You'd need similar code for each of the Textboxes.

    The second way would be to use a single Command Button with code like this:

    Code:
    Private Sub cmdNowButton_Click()
     Screen.PreviousControl = Now()
    End Sub

    After clicking into one of the DateTime Textboxes, you click the Command Button, and the date and time is filled into whichever Control last had the Focus.

    Personally, I would use the first method.

    Linq :0)>

  6. #6
    DonBobCliff is offline Novice
    Windows 8 Access 2000
    Join Date
    May 2014
    Location
    Vermillion, SD
    Posts
    3
    Ok, I chose to work ItsMe's suggestion only because it was first. It worked perfectly. I do however like the suggestions from "Missinglinq" and will be using them in a different task of the database. I am so grateful to you both for your help and will be asking a lot of questions from here on out. This was my first attempt at getting the information from other users on the internet and I can see this is a great forum. This thread is resolved. Thanks a ton!

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 1
    Last Post: 01-16-2014, 12:33 PM
  2. Replies: 8
    Last Post: 10-24-2012, 12:47 PM
  3. Replies: 11
    Last Post: 03-29-2012, 02:32 PM
  4. Replies: 0
    Last Post: 01-11-2012, 12:34 PM
  5. Replies: 13
    Last Post: 07-27-2011, 12:38 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums