Results 1 to 5 of 5
  1. #1
    chrisjack001 is offline Novice
    Windows XP Access 2007
    Join Date
    Aug 2010
    Posts
    12

    Populate Date field (CurrentDate + 30) in table if blank

    I have a "Print" button on a Form called "Invoices" that that has embedded macros on the click event I want to replace with VB code due to the limitation in Macro. Currently this Macro does the following

    1. Opens and runs a query called "SubtotalUpdate"
    2. Opens and runs a query called "InvoiceTotalAppend"
    3. Opens and populates a Report called "Invoices" with the DueDate from "Invoices" table before printing.
    This is what I want to add to the existing macro all converted to VB code
    4. If the DueDate field is blank in the "Invoices" table I want the date saved in that blank field in the table as (Current date + 30 days) before executing option 3. The format of the date should be mm/dd/yyyy. Can I replace this macro with a VB code. Can you please help with the code on Click event.


    Thanks

  2. #2
    weekend00 is offline I may not be right
    Windows XP Access 2003
    Join Date
    Aug 2010
    Posts
    1,295
    private sub command0_click()
    docmd.openquery "SubtotalUpdate"
    docmd.openquery "InvoiceTotalAppend"
    docmd.runsql "update invoices set duedate=date()+30 where duedate is null"
    docmd.openquery "invoices"
    end sub

  3. #3
    chrisjack001 is offline Novice
    Windows XP Access 2007
    Join Date
    Aug 2010
    Posts
    12
    Should I paste the code as it is. It is suppose to populate the Duedate field in the Invoices Table. I dont have a query called "Invoices" as in your code. I have a table. Should I Leave the query names in double quotations as you have in the code. Please be patient with me Im new at all this Access and VB stuff.
    Thanks

  4. #4
    weekend00 is offline I may not be right
    Windows XP Access 2003
    Join Date
    Aug 2010
    Posts
    1,295
    Sorry, the last one is report, not query.
    just paste the code, but you may not need the 2 lines in blue because when you create an event, these 2 line will be generated by Access.

    private sub command0_click()
    docmd.openquery "SubtotalUpdate"
    docmd.openquery "InvoiceTotalAppend"
    docmd.runsql "update invoices set duedate=date()+30 where duedate is null"
    docmd.openreport "invoices",acViewPreview
    end sub

  5. #5
    weekend00 is offline I may not be right
    Windows XP Access 2003
    Join Date
    Aug 2010
    Posts
    1,295
    May I mark it as solved?

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

Similar Threads

  1. Populate field from field on previous record
    By randolphoralph in forum Forms
    Replies: 7
    Last Post: 03-04-2011, 11:28 AM
  2. Adding field to form causes blank view.
    By emccalment in forum Access
    Replies: 1
    Last Post: 04-02-2010, 06:27 PM
  3. ODBC table read to blank Access table write
    By dibblejon in forum Access
    Replies: 2
    Last Post: 03-10-2010, 08:39 AM
  4. validation to populate date?
    By andyf80 in forum Access
    Replies: 3
    Last Post: 02-26-2010, 09:53 PM
  5. Populate date from previous record
    By Lianes in forum Access
    Replies: 3
    Last Post: 09-19-2009, 03:42 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