Results 1 to 9 of 9
  1. #1
    tonybrecko is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jun 2013
    Posts
    6

    Enter current date and time into subform field

    I have a subform with a field which, when clicked, I would like the current date to be inserted.

    I want to keep this form as simple as possibe.

    I got this code to work from the sub form:

    Private Sub StartTime_Click()
    Forms!frm_TimeLogSub![StartTime] = Now()


    End Sub

    but when I open the main form and click on the field I get a run-time error the the application can not find the referenced form.

    Any help would be appreciated!

    Regards, Tony Brecko

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,930
    Are you using the Click event of the textbox?

    Me!StartTime = Now()
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    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
    If you want to keep it as a simple as possible and you want the time/date to reflect when the Record is added, you could use the =Now in the Default Value Property of the Textbox' and the user wouldn't even have to click into the box!

    Linq ;0)>
    The problem with making anything foolproof...is that fools are so darn ingenious!

    All posts/responses based on Access 2003/2007

  4. #4
    tonybrecko is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jun 2013
    Posts
    6
    Quote Originally Posted by Missinglinq View Post
    If you want to keep it as a simple as possible and you want the time/date to reflect when the Record is added, you could use the =Now in the Default Value Property of the Textbox' and the user wouldn't even have to click into the box!

    Linq ;0)>
    Yeah, I tried that. The problem is that i want the user to alternate input between StartTime and EndTime. So the default value doesn't really apply.

  5. #5
    tonybrecko is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jun 2013
    Posts
    6
    I am using the onClick property of the text box in the sub form. And it works fine when using the sub form direct, but when using the main form it throws an error.

    I am not sure what you mean by:

    Me!StartTime = Now()



  6. #6
    Join Date
    May 2013
    Location
    Dallas TX
    Posts
    1,742
    Remember, a subform is NOT a member of the Forms collection. It is more like a control on the form.

    That's why this syntax works on the subform when it's a main form, but doesn't work as a subform:
    Forms!frm_TimeLogSub![StartTime] = Now()

    Use June7's code and it will work both ways. That's because, in code inside a control, Mrefers to the form or subform the control is on. Should work with a period instead of an exclamation mark, too.

    But, if you are trying to capture the start time, I don't understand why the user would have to click anything at all.

  7. #7
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,930
    What do you mean by 'alternate input between StartTime and EndTime'? What does the date input represent? Start or End of what? Why would you want anything other than the current date/time, whether by DefaultValue or code?

    Are you creating new record or updating a date field for existing records?

    If you want to provide db with attempted code for analysis, follow instructions at bottom of my post.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  8. #8
    Join Date
    May 2013
    Location
    Dallas TX
    Posts
    1,742
    OKay, so you can use June7's suggestion in the same place as your code that throws an error -
    Code:
    Me!StartTime = Now()
    Or you can let us walk you through your form design and see if we can give you a better architecture. Your choice.

  9. #9
    tonybrecko is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jun 2013
    Posts
    6
    Thanks to all. Yes I got June7's code to work like a charm.

    Just for clarification the reason that a default value wasn't appropriate is that in the sub form there is both a start and end time. I want the user to be able to click in the start time at the beginning of the job and then close the form and at the end of the job again open the form but this time click in the end time field.

    I really do appreciate the quick help you all gave.

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

Similar Threads

  1. Replies: 6
    Last Post: 12-11-2012, 09:40 PM
  2. Replies: 2
    Last Post: 08-12-2012, 10:56 AM
  3. Using Make Table to Enter as Date/Time and Not Binary
    By Jerseynjphillypa in forum Queries
    Replies: 2
    Last Post: 06-20-2012, 11:30 AM
  4. Automatically enter today's date when entering time
    By Szabi in forum Database Design
    Replies: 5
    Last Post: 03-16-2012, 03:50 AM
  5. VB coding to show current date n time in access form
    By cwwaicw311 in forum Programming
    Replies: 6
    Last Post: 02-10-2010, 09:53 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