Results 1 to 5 of 5
  1. #1
    82280zx's Avatar
    82280zx is offline Advanced Beginner
    Windows 7 64bit Access 2019
    Join Date
    Jan 2014
    Posts
    82

    Update date to now () in query based on a button click?

    It's been a little while since I've played in access so I'm a bit rusty, Is there a way to update my queries data field called txtDateEmailed to now() on a click of a button? I can do it on a single record using
    Code:
    me.txtDateEmailed=now()
    I've also tried this
    Code:
    [FRM_FilterByCompany]![FRM_FilterByCompanySubForm].[txtDateEmailed] = Now()
    So the main form is called FRM_FilterByCompany and has a subform in it called FRM_FilterByCompanySubForm and in that subform it has a datafield I want update called txtDateEmailed. Thanks in advance!

  2. #2
    Micron is offline Very Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    13,423
    In your button click event, execute an Update query on the table for the subform. That query would likely need criteria so that you only update records that relate to the key value in the main form record. You'd also need to refer to fields on the form(s) to get at the form values for the criteria. If you don't use criteria, you'll update all subform table records to Now().

    Running action queries from code will raise prompts. If you don't want to see them, turn off warnings (but use a properly written error handler to ensure they're turned back on) or use .Execute method of the CurrentDb object. You can also execute query sql from code. Easier to use .Excecute but also possible to modify the sql property of a stored query then run that. That would not be my first choice.
    Last edited by Micron; 09-11-2022 at 09:58 AM. Reason: clarification
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  3. #3
    82280zx's Avatar
    82280zx is offline Advanced Beginner
    Windows 7 64bit Access 2019
    Join Date
    Jan 2014
    Posts
    82
    Quote Originally Posted by Micron View Post
    In your button click event, execute an Update query on the table for the subform. That query would likely need criteria so that you only update records that relate to the key value in the main form record. You'd also need to refer to fields on the form(s) to get at the form values for the criteria. If you don't use criteria, you'll update all subform table records to Now().

    Running action queries from code will raise prompts. If you don't want to see them, turn off warnings (but use a properly written error handler to ensure they're turned back on) or use .Execute method of the CurrentDb object. You can also execute query sql from code. Easier to use .Excecute but also possible to modify the sql property of a stored query then run that. That would not be my first choice.
    I guess I'm a bit lost on this, I'm still new with all this. So I have a Form that filters a subform query to list the data I want to use, when I click the email button it generates pdf reports for just that query... but I'd also like to time stamp the filtered data (there is a table record called "Date Emailed" to now() ) I'm able to do this on single records but I guess I'm having trouble time stamping multiple records? Or I'm not sure where to start on that.

  4. #4
    Micron is offline Very Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    13,423
    Copy your tables before experimenting. Work on the originals, otherwise you'll have to deal with everything that won't work with the copied table name.
    The idea would be something like this in the query sql:

    UPDATE mySubformTable SET mySubformTable.DateFieldNameHere = Now() WHERE mySubformTable.CompanyField = Forms!myForm!mysubformControlName.Form.ControlNameThatContainsCompanyData AND...

    You don't change the red word; you do change my references to the names of your objects. The AND is because I figure that surely more than one criteria will be required. The reference to subform controls is like
    [Forms]![Main form name]![subform control name].[Form]![control name on subform]

    Best that you use query design builder I think, rather than trying to write your own sql. The end result would be similar however. If you don't know how to create an update query in Access, Google that and try something on your tables (remember to create copies of them first). If it bombs, you can dump the tables and make new copies from your backup (copied) tables.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  5. #5
    82280zx's Avatar
    82280zx is offline Advanced Beginner
    Windows 11 Access 2019
    Join Date
    Jan 2014
    Posts
    82
    Quote Originally Posted by Micron View Post
    Copy your tables before experimenting. Work on the originals, otherwise you'll have to deal with everything that won't work with the copied table name.
    The idea would be something like this in the query sql:

    UPDATE mySubformTable SET mySubformTable.DateFieldNameHere = Now() WHERE mySubformTable.CompanyField = Forms!myForm!mysubformControlName.Form.ControlNameThatContainsCompanyData AND...

    You don't change the red word; you do change my references to the names of your objects. The AND is because I figure that surely more than one criteria will be required. The reference to subform controls is like
    [Forms]![Main form name]![subform control name].[Form]![control name on subform]

    Best that you use query design builder I think, rather than trying to write your own sql. The end result would be similar however. If you don't know how to create an update query in Access, Google that and try something on your tables (remember to create copies of them first). If it bombs, you can dump the tables and make new copies from your backup (copied) tables.
    Thank you, I'll give that a shot, it's been probably 5-6 years since I last coded anything in access so it's mostly gone in my head =/.

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

Similar Threads

  1. Replies: 14
    Last Post: 03-15-2018, 08:59 AM
  2. Replies: 2
    Last Post: 07-07-2016, 07:01 PM
  3. On Button Click, Record Date & Time to a Textbox
    By JakeMurray27 in forum Programming
    Replies: 2
    Last Post: 02-20-2016, 04:22 AM
  4. Update Query based on existing date
    By axdxnco in forum Queries
    Replies: 1
    Last Post: 06-12-2013, 02:15 PM
  5. query to update a date based on another date
    By tkendell in forum Access
    Replies: 3
    Last Post: 06-29-2011, 09:32 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