I have inherited an old DB at work and need to make changes to our Audit Pass.Fail rate - FROM 40% to 30%....
I have a select query called, "Q09d2_percent", that calculates a percent and then flags a field called "Follow-up" either "Yes" or "No" based on the "percent" field calculation.The current query
applies a "YES" flag for percents "IIf([Percent]>0.395" or greated than 40%. The query also evaluates other various criteria.
I now need to apply the current level of 40% (0.395) rate to audits with dates less than or equal to =< 08/31/2012 and a 30% (0.295) for dates greater than or equal =>
09/01/2012. I can't just go into the query and update the percent to 0.295 because we need to maintain the exisiting percent for past audits.
In the future the rate will drop to 20% (0.195). So I need to be flexible in my new method.
I want to create a VBA Module to create this query 'Q09d2_percent" and based on the date criteria choose the appropriate rate.
The current table query SQL is:
I am new to VBA and would appreciate any help and guidance provided. I am having difficulty breaking the SQL out into "If Else Then" Statements. Do I run the SQL without the percent and then create the IF ELSE THEN statement for just that part or do I need to break the SQL apart into various IF ELSE THEN statements????
This is what I have so far:
I have a select query called, "Q09d2_percent", that calculates a percent and then flags a field called "Follow-up" either "Yes" or "No" based on the "percent" field calculation.The current query
applies a "YES" flag for percents "IIf([Percent]>0.395" or greated than 40%. The query also evaluates other various criteria.
I now need to apply the current level of 40% (0.395) rate to audits with dates less than or equal to =< 08/31/2012 and a 30% (0.295) for dates greater than or equal =>
09/01/2012. I can't just go into the query and update the percent to 0.295 because we need to maintain the exisiting percent for past audits.
In the future the rate will drop to 20% (0.195). So I need to be flexible in my new method.
I want to create a VBA Module to create this query 'Q09d2_percent" and based on the date criteria choose the appropriate rate.
The current table query SQL is:
Code:
SELECT Q09d1_amount_summary.[Audit Review Number], IIf([Q09d1_amount_summary]![SumOfBilled_Amount]=0,0,[Q09d1_amount_summary]![SumOfVariance]/[Q09d1_amount_summary]![SumOfBilled_Amount]) AS [Percent], IIf([Percent]>0.395 Or [Percent]<-0.395,"Yes","No") AS [Follow-up], Q09b_Total_Cases.[Total Cases], Q09c_Cases_Reviewed.[Cases Reviewed], [Total Cases]-[Cases Reviewed] AS Difference, Q09d1_amount_summary.Ready, Q09d1_amount_summary.Audit_Type, IIf([Q09d1_amount_summary]![SumOfOld_Billed_amount]=0,0,[Q09d1_amount_summary]![SumOfOld_Varience]/[Q09d1_amount_summary]![SumOfOld_Billed_amount]) AS Old_Percent
FROM (Q09d1_amount_summary INNER JOIN Q09b_Total_Cases ON Q09d1_amount_summary.[Audit Review Number] = Q09b_Total_Cases.[Audit Review Number]) INNER JOIN Q09c_Cases_Reviewed ON Q09d1_amount_summary.[Audit Review Number] = Q09c_Cases_Reviewed.[Audit Review Number]
WHERE (((Q09d1_amount_summary.Ready)="Yes"));
I am new to VBA and would appreciate any help and guidance provided. I am having difficulty breaking the SQL out into "If Else Then" Statements. Do I run the SQL without the percent and then create the IF ELSE THEN statement for just that part or do I need to break the SQL apart into various IF ELSE THEN statements????
This is what I have so far:
Code:
Option Compare Database
Option Explicit
Private Sub cmdRun_MakePercentQuery()
End Sub
'declare variables to provide rates
Dim db As DAO.Database
Dim qdf As DAO.QueryDef
Dim Rate40 As Double
Dim Rate30 As Integer
Dim Rate20 As Integer
Rate40 = 0.395
Rate30 = 0.295
Rate20 = 0.195
Set db = CurrentDb()
'The next line creates and automatically appends the QueryDef.
Set qdf = db.CreateQueryDef("Q09d2_percent")
'Set the SQL property to a string representing a SQL statement.
qdf.SQL = SELECT Q09d1_amount_summary.[Audit Review Number], IIf([Q09d1_amount_summary]![SumOfBilled_Amount]=0,0,[Q09d1_amount_summary]![SumOfVariance]/[Q09d1_amount_summary]![SumOfBilled_Amount]) AS [Percent], IIf([Percent]>0.395 Or [Percent]<-0.395,"Yes","No") AS [Follow-up], Q09b_Total_Cases.[Total Cases], Q09c_Cases_Reviewed.[Cases Reviewed], [Total Cases]-[Cases Reviewed] AS Difference, Q09d1_amount_summary.Ready, Q09d1_amount_summary.Audit_Type, IIf([Q09d1_amount_summary]![SumOfOld_Billed_amount]=0,0,[Q09d1_amount_summary]![SumOfOld_Varience]/[Q09d1_amount_summary]![SumOfOld_Billed_amount]) AS Old_Percent
FROM (Q09d1_amount_summary INNER JOIN Q09b_Total_Cases ON Q09d1_amount_summary.[Audit Review Number] = Q09b_Total_Cases.[Audit Review Number]) INNER JOIN Q09c_Cases_Reviewed ON Q09d1_amount_summary.[Audit Review Number] = Q09c_Cases_Reviewed.[Audit Review Number]
WHERE (((Q09d1_amount_summary.Ready)="Yes"));
If [MaxAuditMonthYear] <= #08/31/2012# Then 0.395
Else
If [MaxAuditMonthYear >= #09/01/2012# Then 0.295
End If