mikenelena
Board Regular
- Joined
- Mar 5, 2018
- Messages
- 139
- Office Version
- 365
- Platform
- Windows
We have a complicated series of queries for generating invoices, and it takes a good 20-30 seconds to generate an invoice, depending on how long ago the service assignment was received. I am looking to change a single parameter to speed this query, but I'm a bit intimidated by the length of the statement. I simply don't have experience translating that much SQL into VBA syntax.
I am looking to use code similar to the following to change this one parameter.
based on the date an assignment was received. (A control on a form.)
Here is the SQL:
Is this the right way to go about this? What is the easiest way to get the syntax correct on a long statement like this?
Thanks!
I am looking to use code similar to the following to change this one parameter.
SQL:
HAVING (((ClaimInfo1.Date_Received)>Now()-100))
VBA Code:
Private Sub Form_Current()
Dim sql As String
Dim db As dao.Database
Set db = CurrentDb
Dim qdf As dao.QueryDef
Set qdf = db.QueryDefs("AdjusterFileHistory")
qdf.sql = "Select * From [AdjusterFileHistoryHelp] WHERE [Adjuster Name]=Forms.Clients3.frmBranches.Form.Subformcontainer.Form.[AdjusterFirstLast] And [Canceled] = False AND [Invoice_Number] like '*-01'"
Me.txtListCount = Me.FileList.ListCount
End Sub
Here is the SQL:
SQL:
SELECT ClaimInfo1.Date_Received, ClaimInfo1.File_Number, ClaimInfo1.[Date Of Loss], ClaimInfo1.[Claim Number], ClaimInfo1.[Field Work Appraiser], [Service Fee]*[Qty]+[Other Charges$]+[Miles_Charged]*[per mile]+[Discount$]+[Toll_Charges] AS [Total Charges], IIf([Service Fee]<-[Discount$],0,IIf([State_Match]="WV",([Service Fee]*[Qty]+[Other Charges$]+[Discount$])*0.06,0)) AS [WV State Sales Tax], ClaimInfo2.[Service Fee], ClaimInfo2.Miles_Charged, ClaimInfo2.Miles_Traveled, ClaimInfo2.[Other Charges$], ClaimInfo2.[Other Charges Description], ClaimInfo1.[Report Appraiser], ClaimInfo1.[Vehicle Owner], ClaimInfo1.[Client Name], ClaimInfo1.[Insured Names], ClaimInfo1.[Adjuster Name], ClaimInfo1.Invoice_Number, First(ClaimInfo1.[Invoice Notes]) AS [FirstOfInvoice Notes], ClaimInfo1.[Adjuster Name], Appraisers.email3, ClaimInfo1.Invoice_Date, ClaimInfo1.Canceled, tblItems.Service_Item, ClaimInfo2.Qty, ClaimInfo2.[Discount$], Appraisers.Appraiser_Phone, Appraisers.Cell_Phone, ClaimInfo2.[per mile], ClaimInfo2.[Discount Description], ClaimInfo2.Item_Code, ClaimInfo2.Toll_Charges, ClaimInfo2.[Toll Charges Description], ClaimInfo1.[Total Loss], ClaimInfo1.[Total Damages], ClaimInfo1.Zip, tblZip_State.State_Match, ClaimInfo1.Non_Billable, ClaimInfo1.chkTransfer, qryAdjusterClientBranch.[Full Name], qryAdjusterClientBranch.AdjusterFirst, qryAdjusterClientBranch.AdjusterLast, qryAdjusterClientBranch.AdjusterSuffix, qryAdjusterClientBranch.Title, qryAdjusterClientBranch.Street, qryAdjusterClientBranch.Suite, qryAdjusterClientBranch.City, qryAdjusterClientBranch.State, qryAdjusterClientBranch.ZipCode, qryAdjusterClientBranch.BillingAddress, qryAdjusterClientBranch.ClientInactive, qryAdjusterClientBranch.AdjusterInactive, qryAdjusterClientBranch.Email, qryAdjusterClientBranch.EmailType, qryAdjusterClientBranch.BulkBilling
FROM qryAdjusterClientBranch INNER JOIN ((((ClaimInfo1 LEFT JOIN ClaimInfo2 ON ClaimInfo1.[Invoice_Number] = ClaimInfo2.[Invoice_Number]) LEFT JOIN tblItems ON ClaimInfo2.Item_Code = tblItems.Item_Code1) LEFT JOIN tblZip_State ON ClaimInfo1.Zip = tblZip_State.Loss_Zip) LEFT JOIN Appraisers ON ClaimInfo1.[Field Work Appraiser] = Appraisers.[Appraiser Name]) ON (qryAdjusterClientBranch.ClientName = ClaimInfo1.[Client Name]) AND (qryAdjusterClientBranch.[Full Name] = ClaimInfo1.[Adjuster Name])
GROUP BY ClaimInfo1.Date_Received, ClaimInfo1.File_Number, ClaimInfo1.[Date Of Loss], ClaimInfo1.[Claim Number], ClaimInfo1.[Field Work Appraiser], [Service Fee]*[Qty]+[Other Charges$]+[Miles_Charged]*[per mile]+[Discount$]+[Toll_Charges], IIf([Service Fee]<-[Discount$],0,IIf([State_Match]="WV",([Service Fee]*[Qty]+[Other Charges$]+[Discount$])*0.06,0)), ClaimInfo2.[Service Fee], ClaimInfo2.Miles_Charged, ClaimInfo2.Miles_Traveled, ClaimInfo2.[Other Charges$], ClaimInfo2.[Other Charges Description], ClaimInfo1.[Report Appraiser], ClaimInfo1.[Vehicle Owner], ClaimInfo1.[Client Name], ClaimInfo1.[Insured Names], ClaimInfo1.Invoice_Number, ClaimInfo1.[Adjuster Name], Appraisers.email3, ClaimInfo1.Invoice_Date, ClaimInfo1.Canceled, tblItems.Service_Item, ClaimInfo2.Qty, ClaimInfo2.[Discount$], Appraisers.Appraiser_Phone, Appraisers.Cell_Phone, ClaimInfo2.[per mile], ClaimInfo2.[Discount Description], ClaimInfo2.Item_Code, ClaimInfo2.Toll_Charges, ClaimInfo2.[Toll Charges Description], ClaimInfo1.[Total Loss], ClaimInfo1.[Total Damages], ClaimInfo1.Zip, tblZip_State.State_Match, ClaimInfo1.Non_Billable, ClaimInfo1.chkTransfer, qryAdjusterClientBranch.[Full Name], qryAdjusterClientBranch.AdjusterFirst, qryAdjusterClientBranch.AdjusterLast, qryAdjusterClientBranch.AdjusterSuffix, qryAdjusterClientBranch.Title, qryAdjusterClientBranch.Street, qryAdjusterClientBranch.Suite, qryAdjusterClientBranch.City, qryAdjusterClientBranch.State, qryAdjusterClientBranch.ZipCode, qryAdjusterClientBranch.BillingAddress, qryAdjusterClientBranch.ClientInactive, qryAdjusterClientBranch.AdjusterInactive, qryAdjusterClientBranch.Email, qryAdjusterClientBranch.EmailType, qryAdjusterClientBranch.BulkBilling, ClaimInfo2.Appraiser
HAVING (((ClaimInfo1.Date_Received)>Now()-100))
ORDER BY ClaimInfo1.File_Number;
Is this the right way to go about this? What is the easiest way to get the syntax correct on a long statement like this?
Thanks!