Solved

MSAcess VBA Running Update Query with a Variable

Posted on 2014-09-10
1
146 Views
Last Modified: 2014-09-10
I am trying to update a table based upon a single variable that is calculated from the date difference between two dates. If I replace the variable AccrualFrac with an actual Fraction the code works fine. It prompts for a parameter the way I currently have it, and if I input a legitimate number it executes fine. The code snippet is attached along with the Immediate Window which shows the SQL that is being run:

If chkdate + 14 > MEndDate Then
' \ Calculate the Actual Accrual Fraction
    AccrualFrac = (MEndDate - PEnddate) / DaysInMonth(PEnddate)
   
    TBCOSQL = "DELETE AJEWORK_ACCRUAL.* "
    TBCOSQL = TBCOSQL & "FROM AJEWORK_ACCRUAL"
   
    DoCmd.RunSQL TBCOSQL
       
       
    TBCOSQL = "INSERT INTO AJEWORK_ACCRUAL ( End_Date, Entity, AcctNo, AJE_AMT ) "
    TBCOSQL = TBCOSQL & "SELECT AJEWORK.End_Date, AJEWORK.Entity, AJEWORK.AcctNo, AJEWORK.AJE_AMT "
    TBCOSQL = TBCOSQL & "FROM AJEWORK "
    TBCOSQL = TBCOSQL & "WHERE (((AJEWORK.AcctNo) Like '5*' Or (AJEWORK.AcctNo) Like '6*' Or (AJEWORK.AcctNo) Like '7*' Or (AJEWORK.AcctNo) Like '8*' Or (AJEWORK.AcctNo) Like '9*'))"

    DoCmd.RunSQL TBCOSQL
   
'\ Modify the amounts to the correct amount of accrual based upon the payroll date

TBCOSQL = "UPDATE AJEWORK_ACCRUAL SET AJEWORK_ACCRUAL.AJE_AMT = " & "[AJEWORK_ACCRUAL]![AJE_AMT]" & " * " & "AccrualFrac"

Debug.Print TBCOSQL



DoCmd.RunSQL TBCOSQL


The Immediate Window:

UPDATE AJEWORK_ACCRUAL SET AJEWORK_ACCRUAL.AJE_AMT = [AJEWORK_ACCRUAL]![AJE_AMT] * AccrualFrac
0
Comment
Question by:rrudolph
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 120

Accepted Solution

by:
Rey Obrero (Capricorn1) earned 500 total points
ID: 40315820
try this

TBCOSQL = "UPDATE AJEWORK_ACCRUAL SET AJEWORK_ACCRUAL.AJE_AMT =  [AJEWORK_ACCRUAL]![AJE_AMT]" & "*" & AccrualFrac
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In a multiple monitor setup, if you don't want to use AutoCenter to position your popup forms, you have a problem: where will they appear?  Sometimes you may have an additional problem: where the devil did they go?  If you last had a popup form open…
Describes a method of obtaining an object variable to an already running instance of Microsoft Access so that it can be controlled via automation.
Learn how to number pages in an Access report over each group. Activate two pass printing by referencing the pages property: Add code to the Page Footers OnFormat event to capture the pages as there occur for each group. Use the pages property to …
Basics of query design. Shows you how to construct a simple query by adding tables, perform joins, defining output columns, perform sorting, and apply criteria.

710 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question