Results 1 to 4 of 4
  1. #1
    Join Date
    Feb 2019
    Posts
    1,046

    Need Assistance with Modifying CurrentDb.Execute in Order to Append Date <> "12/30/1899"

    Hello Experts:

    I need to obtain some assistance with tweaking my *CurrentDb.Execute* routine in order to append the correct date (from an unbound control).

    Process:
    1. Open form "F01_MainMenu"
    2. Click on green command button "Run Append" (top right)
    3. Close form


    4. Open table "tbl_MonthlyBills"
    4a. For each click on the command button (form), a record has been inserted.
    4b. The problem is the date where [PAYDATE] = "12/30/1899"

    Additional information:
    - For testing only, now execute query "qryAppend".
    - Here, a record has been inserted into "tbl_MonthlyBills" where [PAYDATE] = today's date. I do NOT want that either!!

    VBA Background:
    - In form "F01_MainMenu", I added the SQL from "qryAppend" into CurrentDb.Execute
    - Then, I changed "SELECT qry_Payees_First_Half_Crosstab.Date,..." to "SELECT " & txt_Date_22nd & "
    - ... where the unbound control "txt_Date_22nd" stores the desired date (i.e., "2/22/2024").
    - Please note, when clicking the green "Run Append", a test message box is thrown displaying the date verifying the control stores the correct date.

    My question:
    How do I need to modify the CurrentDb.Execute line so that I append the value of "txt_Date_22nd" ("2/22/2024") vs. "12/30/1899" into the table?

    Code:
    '    Original SQL from the append query
    '    Original SQL from the append query
    '    CurrentDb.Execute "INSERT INTO tbl_MonthlyBills ( PAYDATE, 3676_SAVINGS, 4011_BILLPAY, TOTAL ) " & _
    '                      "SELECT qry_Payees_First_Half_Crosstab.Date, qry_Payees_First_Half_Crosstab.[3676 (Savings)], qry_Payees_First_Half_Crosstab.[4011 (Bill Pay)], qry_Payees_First_Half_Crosstab.TotalExpenses " & _
    '                      "FROM qry_Payees_First_Half_Crosstab;
    Code:
        'Changed from: "SELECT qry_Payees_First_Half_Crosstab.Date,..."
        'To:           "SELECT " & txt_Date_22nd & ",
        CurrentDb.Execute "INSERT INTO tbl_MonthlyBills ( PAYDATE, 3676_SAVINGS, 4011_BILLPAY, TOTAL ) " & _
                          "SELECT " & txt_Date_22nd & ", qry_Payees_First_Half_Crosstab.[3676 (Savings)], qry_Payees_First_Half_Crosstab.[4011 (Bill Pay)], qry_Payees_First_Half_Crosstab.TotalExpenses " & _
                          "FROM qry_Payees_First_Half_Crosstab;"
    Attached Thumbnails Attached Thumbnails Illustration.png  
    Attached Files Attached Files

  2. #2
    davegri's Avatar
    davegri is offline Excess Access
    Windows 11 Access 2019
    Join Date
    May 2012
    Location
    Denver
    Posts
    3,413
    I would give this a try:

    Name that field:
    "SELECT " & txt_Date_22nd & " As PAYDATE, qry_Payees_First_Half_Crosstab.[3676 (Savings)],


    You may need delimiters:
    "SELECT #" & txt_Date_22nd & "# As PAYDATE, qry_Payees_First_Half_Crosstab.[3676 (Savings)],

  3. #3
    Join Date
    Feb 2019
    Posts
    1,046
    Davegri -- thank you for the prompt response.

    The 2nd option (with delimiters) works great! Many thanks!!!
    Attached Thumbnails Attached Thumbnails Delimiters.png  

  4. #4
    davegri's Avatar
    davegri is offline Excess Access
    Windows 11 Access 2019
    Join Date
    May 2012
    Location
    Denver
    Posts
    3,413
    Quote Originally Posted by skydivetom View Post
    Davegri -- thank you for the prompt response.

    The 2nd option (with delimiters) works great! Many thanks!!!
    Happy to help and thanks for the star!

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

Similar Threads

  1. Format(Date,"mm/dd/yyyy") = 12/30/1899
    By GraeagleBill in forum Programming
    Replies: 14
    Last Post: 03-29-2022, 12:21 PM
  2. Replies: 2
    Last Post: 01-23-2018, 09:11 AM
  3. sort order of the date is "slightly" off...
    By markjkubicki in forum Queries
    Replies: 14
    Last Post: 06-16-2015, 12:36 PM
  4. Replies: 2
    Last Post: 06-25-2014, 11:00 AM
  5. Problems with CurrentDb.Execute "UPDATE
    By GraeagleBill in forum Programming
    Replies: 4
    Last Post: 04-06-2013, 03:21 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