The below SQL query has a syntax error, how can I solve it?
SELECT [CREDITORS$].[Account Code], [CREDITORS$].[Name], Sum([CREDITORS$]![Base Amount]*-1) AS BillAmt," & _
"SUM([SERVICETAX$].[Base Amount]) AS STAMT, Sum(([CREDITORS$]![Base Amount]*-1)-[SERVICETAX$]![Base Amount]) AS TDS " & _
"FROM [CREDITORS$] LEFT JOIN [SERVICETAX$] ON [CREDITORS$].[Transaction Reference]=[SERVICETAX$].[Transaction Reference]" & _
"LEFT JOIN [MASTER$] ON [MASTER$].[Account Code]=[CREDITORS$].[Account Code]" & _
"GROUP BY [CREDITORS$].[Account Code], [CREDITORS$].[Name];
On a dynamic query you need add space in before of LEFT JOIN and GROUP BY, that was missed in the query. So adding the space in end of the line will work.
So the below query will work:
"SELECT [CREDITORS$].[Account Code], [CREDITORS$].[Name], Sum([CREDITORS$]![Base Amount]*-1) AS BillAmt, " & _
"SUM([SERVICETAX$].[Base Amount]) AS STAMT, Sum(([CREDITORS$]![Base Amount]*-1)-[SERVICETAX$]![Base Amount]) AS TDS " & _
"FROM [CREDITORS$] LEFT JOIN [SERVICETAX$] ON [CREDITORS$].[Transaction Reference]=[SERVICETAX$].[Transaction Reference] " & _
"LEFT JOIN [MASTER$] ON [MASTER$].[Account Code]=[CREDITORS$].[Account Code] " & _
"GROUP BY [CREDITORS$].[Account Code], [CREDITORS$].[Name];"
You actual query will return as the below, it won't have proper spacing.
SELECT [CREDITORS$].[Account Code], [CREDITORS$].[Name], Sum([CREDITORS$]![Base Amount]*-1) AS BillAmt, SUM([SERVICETAX$].[Base Amount]) AS STAMT, Sum(([CREDITORS$]![Base Amount]*-1)-[SERVICETAX$]![Base Amount]) AS TDS FROM [CREDITORS$] LEFT JOIN [SERVICETAX$] ON [CREDITORS$].[Transaction Reference]=[SERVICETAX$].[Transaction Reference]LEFT JOIN [MASTER$] ON [MASTER$].[Account Code]=[CREDITORS$].[Account Code]GROUP BY [CREDITORS$].[Account Code], [CREDITORS$].[Name];
Related
I am trying to add a filter criteria for the current fiscal year in a WHERE statement in my code. However, I don't know how to integrate the CASE statement in my WHERE clause in VBA. Here's the code that I am working on:
Source = "SELECT tblretirements.retirementID As `RetirementID`,tblretirements.InputBy As `Input By`, tblretirements.ReceiptDate As `Date Received` , tblretirements.FirstName As `First Name`, tblretirements.LastName As `Last Name`, tblretirements.DateOfBirth As `DOB`, tblretirements.DateOfRetirement As `Retirement Date`, tblBenefitInProcress.RetirementDescription As `Retirement Type`, tblretirements.MemberPIN As `Pin`, tblcurrentplan.CurrentPlan As `Current Plan`, tblretirements.ServiceCredits As `Service Crdits w/o PS/AC`, tblretirements.MultiplePlans As `Multiple Plans/Tiers?`, " & _
" tblretirements.ConfirmationLetterMailed As `Mailed Confirm Letter`, tblretirements.WorkbookSetup As `Set Up Excel Workbook`, tblCalculationTeam.CalcTeam As `Calculation Team`, tblCalculationPersonnel.Name As `Assigned Staff`, tblretirements.ReviewDate As`Review Date`, tblBoardStatus.StatusReported As`BoardStatusID`, tblretirements.ReciprocityID As `Reciprocity?`, tblretirements.EmployerCodeID As `Employer`, " & _
" tblDepartment.DepartmentName As `Department`, tblretirements.PendingPurchase As `Pending Purchase(s)?`, tblJoinder.Joinder As `Joinder or Pending DRO?`, tblDisabilityPending.AgendaDisability As `DisabilityID`, tblReciprocity.ReciprocalStatus, tblOrientationStatus.OrientationStatus As `Orientation Elected?`,tblretirements.OrientationDate As `Orientation Date`, tblReviewPersonnel.ReviewerName As `Designated Reviewer`, tblretirements.FileSetupApproved As `File Set-Up Approved`, tblretirements.AgendaApplication As `Agenda Application`, tblretirements.EstimateToReviewer As `Estimate to Reviewer`, tblretirements.EstimateToSupervisor As `Estimate to Supervisor`, " & _
" tblretirements.EstimateApproved As `Estimate Approved`, tblretirements.FinalPaycheck As `Final Paycheck Date`, tblretirements.FinalService As `Final Service with PS/AC`, tblretirements.FinalToReviewer As `Final Calc to Reviewer`, tblretirements.FinalToSupervisor As `Final Calc to Supervisor`, tblretirements.FinalApproved As `Final Calc Approved`, tblretirements.ApplicationCancelled As `App Cancelled by Member?`, tblretirements.RetElectionDistributed As `Retirement Election Distributed`, tblretirements.RetElectionReturned As `Retirement Election Returned`, tblPaymentOption.AgendaOption As `Option/Payment Selected`, " & _
" tblretirements.TempAnnuityID As `Age Request for Temp Annuity`, tblretirements.FinalAllowance As `Final Allowance Calculation`, tblretirements.Continuance As `Continuance`, tblretirements.PayrollFormsStaff As `Payroll Forms Completed (Staff)`, tblretirements.AgendaPayment As `Option-Payment`, tblretirements.PayrollFormsSupervisor As `Payroll Forms Reviewed (Supv)`, " & _
" tblretirements.CboApprovedAllowance As `Allowance Approved (CBO)`, tblretirements.AllowanceEstimated As `Allowance Estimated?`, tblretirements.AllowEnteredInPayroll As `Allowance Entered In Payroll`, tblretirements.DistributionCycleID As `Distribution Cycle for 1st Payment`, " & _
" tblretirements.FirstPayDate As `Distribution Date for 1st Payment`, tblretirements.AllowanceFinalized As `Allowance Finalized`, tblretirements.FileImaged As `Retirement File Imaged`" & _
" FROM ((((((((((((tblRetirements " & _
" LEFT JOIN tblCalculationPersonnel On tblRetirements.CoordinatorID=tblCalculationPersonnel.CoordinatorID) " & _
" LEFT JOIN tblCurrentPlan On tblRetirements.CurrentPlanID=tblCurrentPlan.CurrentPlanID) " & _
" LEFT JOIN tblBenefitInProcress On tblRetirements.BenefitInProcess=tblBenefitInProcress.RetirementTypeID) " & _
" LEFT JOIN tblPaymentOption ON tblretirements.OptionID=tblPaymentoption.OptionID) " & _
" LEFT JOIN tblReviewPersonnel ON tblretirements.ReviewerID=tblReviewPersonnel.ReviewerID) " & _
" LEFT JOIN tblOrientationStatus ON tblretirements.OrientationID=tblOrientationStatus.OrientationID) " & _
" LEFT JOIN tblDisabilityPending ON tblretirements.DisabilityID=tblDisabilityPending.DisabilityID) " & _
" LEFT JOIN tblJoinder ON tblretirements.JoinderID=tblJoinder.JoinderID) " & _
" LEFT JOIN tblDepartment ON tblretirements.DepartmentID=tblDepartment.DepartmentID) " & _
" LEFT JOIN tblEmployerCode ON tblretirements.EmployerCodeID=tblEmployerCode.EmployerCodeID) " & _
" LEFT JOIN tblReciprocity ON tblretirements.ReciprocityID=tblReciprocity.ReciprocityID) " & _
" LEFT JOIN tblCalculationTeam ON tblretirements.CalculationTeamID=tblCalculationTeam.CalculationTeamID) " & _
" LEFT JOIN tblBoardStatus ON tblretirements.BoardStatusID=tblBoardStatus.BoardStatusID " & _
This is what I need assistance with:
" WHERE tblretirements.ApplicationCancelled = 'No' AND (tblretirements.ReceiptDate IS NULL OR tblretirements.ReceiptDate " & _
" BETWEEN (CASE WHEN MONTH(getdate()) < 7 THEN DATEFROMPARTS(YEAR(getdate())-1,7,1) " & _
" ELSE DATEFROMPARTS(YEAR(getdate()),7,1) End ) AND (CASE WHEN MONTH(getdate()) < 7 THEN DATEFROMPARTS(YEAR(getdate()),6,30) " & _
" ELSE DATEFROMPARTS(YEAR(getdate())+1,6,30)End )) "
Can someone please help me? Thank you.
Several issues need attention here:
For complex queries of many joins, do not build SQL on the fly during application code. Save it as stored object in MS Access so the engine can save best execution plan. Then have application, here being Excel, reference the query by name. You can even pass values as parameters to a saved query.
Use table aliases to avoid writing out the long table names for a more readable and maintainable, and less lengthy query.
No two SQL dialects are the same. Even under the same vendor, here being Microsoft. The JET/ACE SQL (Windows .dll files) dialect that MS Access uses is different than the T-SQL dialect that SQL Server uses. Interestingly, another database, Sybase, also uses T-SQL with a history to why.
But like all other dialects (e.g., Oracle, Postgres) though, both share most traditional ANSI SQL functions which is the standard of the language. Therefore, SQL Server's CASE, DATEFROMPARTS(), and GETDATE() must be replaced for Access' IIF(), DATESERIAL(), and DATE(). Interestingly though, CASE is an ANSI method.
Consider the following re-write of your query and specifically the WHERE clause to be saved in MS Access as a stored object.
SQL
SELECT r.retirementid AS `RetirementID`,
r.inputby AS `Input By`,
r.receiptdate AS `Date Received`,
r.firstname AS `First Name`,
r.lastname AS `Last Name`,
r.dateofbirth AS `DOB`,
r.dateofretirement AS `Retirement Date`,
bp.retirementdescription AS `Retirement Type`,
r.memberpin AS `Pin`,
cr.currentplan AS `Current Plan`,
r.servicecredits AS `Service Crdits w/o PS/AC`,
r.multipleplans AS `Multiple Plans/Tiers?`,
r.confirmationlettermailed AS `Mailed Confirm Letter`,
r.workbooksetup AS `Set Up Excel Workbook`,
ct.calcteam AS `Calculation Team`,
co.name AS `Assigned Staff`,
r.reviewdate AS`Review Date`,
bs.statusreported AS`BoardStatusID`,
r.reciprocityid AS `Reciprocity?`,
r.employercodeid AS `Employer`,
d.departmentname AS `Department`,
r.pendingpurchase AS `Pending Purchase(s)?`,
j.joinder AS `Joinder or Pending DRO?`,
dp.agendadisability AS `DisabilityID`,
ry.reciprocalstatus,
o.orientationstatus AS `Orientation Elected?`,
r.orientationdate AS `Orientation Date`,
rp.reviewername AS `Designated Reviewer`,
r.filesetupapproved AS `File Set-Up Approved`,
r.agendaapplication AS `Agenda Application`,
r.estimatetoreviewer AS `Estimate to Reviewer`,
r.estimatetosupervisor AS `Estimate to Supervisor`,
r.estimateapproved AS `Estimate Approved`,
r.finalpaycheck AS `Final Paycheck Date`,
r.finalservice AS `Final Service with PS/AC`,
r.finaltoreviewer AS `Final Calc to Reviewer`,
r.finaltosupervisor AS `Final Calc to Supervisor`,
r.finalapproved AS `Final Calc Approved`,
r.applicationcancelled AS `App Cancelled by Member?`,
r.retelectiondistributed AS `Retirement Election Distributed`,
r.retelectionreturned AS `Retirement Election Returned`,
p.agendaoption AS `Option/Payment Selected`,
r.tempannuityid AS `Age Request for Temp Annuity`,
r.finalallowance AS `Final Allowance Calculation`,
r.continuance AS `Continuance`,
r.payrollformsstaff AS `Payroll Forms Completed (Staff)`,
r.agendapayment AS `Option-Payment`,
r.payrollformssupervisor AS `Payroll Forms Reviewed (Supv)`,
r.cboapprovedallowance AS `Allowance Approved (CBO)`,
r.allowanceestimated AS `Allowance Estimated?`,
r.allowenteredinpayroll AS `Allowance Entered In Payroll`,
r.distributioncycleid AS `Distribution Cycle for 1st Payment`,
r.firstpaydate AS `Distribution Date for 1st Payment`,
r.allowancefinalized AS `Allowance Finalized`,
r.fileimaged AS `Retirement File Imaged`
FROM ((((((((((((tblretirements r
LEFT JOIN tblcalculationpersonnel cp
ON r.coordinatorid = co.coordinatorid)
LEFT JOIN tblcurrentplan cr
ON r.currentplanid = cr.currentplanid)
LEFT JOIN tblbenefitinprocress bp
ON r.benefitinprocess = bp.retirementtypeid)
LEFT JOIN tblpaymentoption p
ON r.optionid = p.optionid)
LEFT JOIN tblreviewpersonnel rp
ON r.reviewerid = rp.reviewerid)
LEFT JOIN tblorientationstatus o
ON r.orientationid = o.orientationid)
LEFT JOIN tbldisabilitypending dp
ON r.disabilityid = dp.disabilityid)
LEFT JOIN tbljoinder j
ON r.joinderid = j.joinderid)
LEFT JOIN tbldepartment dt
ON r.departmentid = d.departmentid)
LEFT JOIN tblemployercode e
ON r.employercodeid = e.employercodeid)
LEFT JOIN tblreciprocity ry
ON r.reciprocityid = ry.reciprocityid)
LEFT JOIN tblcalculationteam ct
ON r.calculationteamid = ct.calculationteamid)
LEFT JOIN tblboardstatus bs
ON r.boardstatusid = bs.boardstatusid
WHERE clause
WHERE r.applicationcancelled = 'No'
AND r.receiptdate IS NULL
OR r.receiptdate BETWEEN (
IIF(MONTH(DATE()) < 7,
DATESERIAL(YEAR(DATE()) - 1, 7, 1),
DATESERIAL(YEAR(DATE()), 7, 1))
)
AND (
IIF(MONTH(DATE()) < 7,
DATESERIAL(YEAR(DATE()), 6, 30),
DATESERIAL(YEAR(DATE()) + 1, 6, 30))
)
IS not clear why you are using case in where but if you want use in between should be
" WHERE tblretirements.ApplicationCancelled = 'No'
AND (tblretirements.ReceiptDate IS NULL OR tblretirements.ReceiptDate BETWEEN
( CASE WHEN MONTH(getdate()) < 7 THEN DATEFROMPARTS(YEAR(getdate())-1,7,1)
ELSE DATEFROMPARTS(YEAR(getdate()),7,1)
End )
AND (
CASE
WHEN MONTH(getdate()) < 7 THEN DATEFROMPARTS(YEAR(getdate()),6,30)
ELSE DATEFROMPARTS(YEAR(getdate())+1,6,30)
End ) ) "
I need to select 5 records from each Startup System ([SU SYS-TO DATE].STARTUP_SYS) based off the most recent or future CURRTARGETCOMPDATE.
I believe I will need to add a subquery to my SQL query, but I am having a hard time figuring out how:
SELECT Friday_Meeting.ID, [SU SYS-TO DATE].STARTUP_SYS, [SU SYS-TO DATE].[FORECAST DATE], TEAMWORKS_24590_TOPUNCHITEM.PUNCHITEM_KEY, TEAMWORKS_24590_TOPUNCHITEM.ORIGINATOR_NAME, TEAMWORKS_24590_TOPUNCHITEM.TAG_NO, TEAMWORKS_24590_TOPUNCHITEM.ENTRYDATE, TEAMWORKS_24590_TOPUNCHITEM.FIELD_ENGINEER, [ITEM_DESCRIPTION1] & " " & [ITEM_DESCRIPTION2] & " " & [TAG_NO] & " " & " " & [CRECORD] AS Description, TEAMWORKS_24590_TOPUNCHITEM.PRIORITY_CODE, [REMARKS1] & " " & [REMARKS2] AS Remarks, TEAMWORKS_24590_TOPUNCHITEM.RESTRAINTS, TEAMWORKS_24590_TOPUNCHITEM.SUPERINTENDENT, TEAMWORKS_24590_TOPUNCHITEM.PIDISCIPLINE, TEAMWORKS_24590_TOPUNCHITEM.CURRTARGETCOMPDATE, TEAMWORKS_24590_TOPUNCHITEM.ORIGTARGETCOMPDATE, TEAMWORKS_24590_TOPUNCHITEM.CRECORD
FROM Friday_Meeting LEFT JOIN ([SU SYS-TO DATE] LEFT JOIN TEAMWORKS_24590_TOPUNCHITEM ON [SU SYS-TO DATE].STARTUP_SYS = TEAMWORKS_24590_TOPUNCHITEM.STARTUP_SYS) ON Friday_Meeting.[SU SYS] = [SU SYS-TO DATE].STARTUP_SYS
WHERE ((([SU SYS-TO DATE].STARTUP_SYS)="MVE-L-01" Or ([SU SYS-TO DATE].STARTUP_SYS)="LVE-A-01" Or ([SU SYS-TO DATE].STARTUP_SYS)="GRE-A-01or LVE-B-03" Or ([SU SYS-TO DATE].STARTUP_SYS)="LVE-B-07" Or ([SU SYS-TO DATE].STARTUP_SYS)="CHW-B-01") AND ((TEAMWORKS_24590_TOPUNCHITEM.PRIORITY_CODE)="A") AND ((TEAMWORKS_24590_TOPUNCHITEM.CURRTARGETCOMPDATE)>=[FORECAST DATE]-14) AND ((TEAMWORKS_24590_TOPUNCHITEM.RECORD_CLOSURE) Is Null) AND ((TEAMWORKS_24590_TOPUNCHITEM.DELETED)="N"))
ORDER BY Friday_Meeting.ID;
I truly appreciate any help and guidance!
I have try to build dropdown list that bind with database. I found out some errors that i dont really found. Please help, here below is my codes.
strSQL = "SELECT distinct table1.DeptName FROM Table1 " & _
"FULL JOIN Table2 on table1.DeptName = Table2.deptname" & _
"FULL JOIN Table3 on Table1.deptname = table3.DeptName " & _
"Where table1.deptname is not null order by table1.deptname "
Common.OpenConn()
Common.execReader(strSQL, params, dt, Common.txn)
If dt.Rows.Count > 0 Then
DropDownListDept.DataSource = dt
DropDownListDept.DataTextField = "DeptName"
DropDownListDept.DataValueField = "DeptName"
DropDownListDept.DataBind()
DropDownListDept.Items.Insert(0, New ListItem("Select Department Name", "0"))
End If
error found
Invalid column name 'DeptNameFULL'.
Your error is in your sql statement... The database is looking for a field called "DeptNameFULL" and of course there isn't.
strSQL = "SELECT distinct table1.DeptName FROM Table1 " & _
"FULL JOIN Table2 on table1.DeptName = Table2.deptname" & _
"FULL JOIN Table3 on Table1.deptname = table3.DeptName " & _
"Where table1.deptname is not null order by table1.deptname "
On the second line - you need a space after "Table2.deptname" - so it should be Table2.deptname " instead.
I have two tables: newparts, storedparts
I insert the parts of the newparts, which are not jet in the storedparts into the storedparts:
SQL_String = "INSERT INTO storedparts " & _
"SELECT newparts.* " & _
"FROM storedparts " & _
"RIGHT JOIN newparts ON (storedparts.identifier = newparts.identifier) AND (storedparts.timeStamp = newparts.timeStamp) " & _
"WHERE ((storedparts.AutoID) Is Null);"
This is working fine so far. Now the Problem: Table storedparts is getting so big that the programm is taking too Long for the join process. My solution: Just compare the newparts not to all parts of the storedparts, but just to parts that aren't older than 4 days... I tried a subquery like this, but i can't get it to run.
SQL_String = "INSERT INTO storedparts " & _
"SELECT newparts.* " & _
"FROM storedparts (WHERE storedparts.timestamp > Now() - 4) " & _
"RIGHT JOIN newparts ON (storedparts.identifier = newparts.identifier) AND (storedparts.timeStamp = newparts.timeStamp) " & _
"WHERE ((storedparts.AutoID) Is Null);"
Any help is appreciated.
This wouldn't be a problem if your tables have indexes.
CREATE INDEX ndx_sp_identifier ON storedparts (identifier);
CREATE INDEX ndx_np_identifier ON newparts (identifier);
Then I suggest you change your query to something like this as #jarlh pointed out.
INSERT INTO storedparts
SELECT newparts.*
FROM newparts
LEFT JOIN storedparts
ON newparts.identifier = storedparts.identifier
AND newparts.timeStamp = storedparts.timeStamp
WHERE storedparts.AutoID Is Null;
You could add the where clause after the join statements and see if it improves the performance of the query . Else Try this and see if it works
SQL_String = "INSERT INTO storedparts " & _
"SELECT newparts.* " & _
"FROM ( SELECT * FROM storedparts WHERE
storedparts.timestamp > DateAdd ( 'd', -4, Now()) )sparts" & _
"RIGHT JOIN newparts ON (sparts.identifier = newparts.identifier) AND
(sparts.timeStamp = newparts.timeStamp) " & _
"WHERE ((sparts.AutoID) Is Null);"
I am getting Runtime error message 3071 on the following query stating that the query is too complex. I have created queries in the past which have seemed more complex than this one. I would like to understand what generates this message:
sql_get = "SELECT tblValueChain01.IDMacroProcesso, tblValueChain02.IDMicroProcesso02, tblValueChain03.ID, tblDependencies01.ID AS DependencyID, tblValueChain02.MicroProcesso02, tblValueChain01.MacroProcess, tblValueChain01.TeamLead, tblValueChain01.LastOrganisationDate, tblValueChain01.TempiIndeterminati, tblValueChain01.TempiDeterminati, tblValueChain01.Interinali, tblValueChain01.PartTime, tblValueChain01.DailyMinutesAverage AS Minutes01, tblValueChain01.DailyMinutesHigh AS Minutes01H, tblValueChain01.DailyMinutesLow AS Minutes01L, tblValueChain02.MicroProcesso02, " & _
"tblValueChain02.DailyMinutesAverage AS Minutes02, tblValueChain02.DailyMinutesHigh AS Minutes02H, tblValueChain02.DailyMinutesLow AS Minutes02L, tblValueChain03.MicroProcess, tblValueChain03.MinutesPerDay AS Minutes03, tblValueChain03.MinutesPerDayHigh AS Minutes03H, tblValueChain03.MinutesPerDayLow AS Minutes03L, tblDependencies01.FlowDescription, tblDependencies01.FlowType, tblTeamsDepartments.Department, tblTeams.Team, tblDependencies01.Precision, " & _
"tblDependencies01.ServiceDelivery , tblDependencies01.RiskReduction, tblDependencies01.CapacityCreation, tblDependencies01.TargetCapacityCreation, tblDependencies01.Feasibility, tblDependencies01.Timeframe, tblDependencies01.Priority, tblDependencies01.Note, tblDependencies01.RedundantControls, tblDependencies01.RedundantControlsNotes, tblDependencies01.RedundantControlsPotSolution, tblDependencies01.RedundantControlsNotesSymbol, tblDependencies01.RedundantControlsPotSolSymbol, tblDependencies01.RolesAndResponsibilities, tblDependencies01.RolesAndResponsibilitiesNotes, " & _
"tblDependencies01.RolesAndResponsibilitiesPotSolution , tblDependencies01.RolesResponNotesSymbol, tblDependencies01.RolesRespPotSolSymbol, tblDependencies01.SubstandardSvcs, tblDependencies01.SubstandardSvcsNotes, tblDependencies01.SubStandardSvcsPotSolution, tblDependencies01.SubStandardSvcsNotesSymbol, tblDependencies01.SubStandardSvcsPotSolSymbol, tblDependencies01.KnowledgeGaps, tblDependencies01.KnowledgeGapsNotes, tblDependencies01.KnowledgeGap, " & _
"PotSolution , tblDependencies01.KnowledgeGapsNotesSymbol, tblDependencies01.KnowledgeGapsPotSolSymbol, tblDependencies01.ExcessiveOversight, tblDependencies01.ExcessiveOversightNotes, tblDependencies01.ExcessiveOversightPotSolution, tblDependencies01.ExcessiveOversightNotesSymbol, tblDependencies01.ExcessiveOversightPotSolSymbol, tblDependencies01.UpstreamErrors, tblDependencies01.UpstreamErrorsNotes, tblDependencies01.UpstreamErrorsPotSolution, tblDependencies01.UpstreamErrorsNotesSymbol, tblDependencies01.UpstreamErrorsPotSolSymbol, tblDependencies01.DefectsRework, " & _
"tblDependencies01.DefectsReworkNotes , tblDependencies01.DefectsReworkPotSolution, tblDependencies01.DefectsReworkNotesSymbol, tblDependencies01.DefectsReworkPotSolSymbol, tblDependencies01.OverProduction, tblDependencies01.OverproductionNotes, tblDependencies01.OverproductionPotSolution, tblDependencies01.OverproductionNotesSymbol, tblDependencies01.OverproductionPotSolSymbol, tblDependencies01.MotionTransport, " & _
"tblDependencies01.MotionTransportNotes , tblDependencies01.MotionTransportPotSolution, tblDependencies01.MotionNotesSymbol, tblDependencies01.MotionSolSymbol, tblDependencies01.DowntimeWaiting, tblDependencies01.DowntimeWaitingNotes, tblDependencies01.DowntimeWaitingPotSolution, tblDependencies01.WaitDowntimeNotesSymbol, tblDependencies01.WaitDowntimeSolSymbol, tblDependencies01.ExcessiveHandoffs, tblDependencies01.ExcessiveHandoffNotes, tblDependencies01.ExcessiveHandoffPotSolution, " & _
"tblDependencies01.ExcessiveHandoffsSymbol , tblDependencies01.ExcessiveHandoffsPotSolSymbol, tblDependencies01.RCSLABreachInternal, tblDependencies01.RCSLABreachExternal, tblDependencies01.RCCorporatePolicyBreach, tblDependencies01.RCOperatingModelDiscrepancy, tblDependencies01.RRSLABreachInternal, tblDependencies01.RRSLABreachExternal, tblDependencies01.RRCorporatePolicyBreach, tblDependencies01.RROperatingModelDiscrepancy, tblDependencies01.SSSLABreachInternal, tblDependencies01.SSSLABreachExternal, tblDependencies01.SSCorporatePolicyBreach, " & _
"tblDependencies01.SSOperatingModelDiscrepancy , tblDependencies01.KGSLABreachInternal, tblDependencies01.KGSLABreachExternal, tblDependencies01.KGCorporatePolicyBreach, tblDependencies01.KGOperatingModelDiscrepancy, tblDependencies01.EOSLABreachInternal, tblDependencies01.EOSLABreachExternal, tblDependencies01.EOCorporatePolicyBreach, tblDependencies01.EOOperatingModelDiscrepancy, tblDependencies01.UESLABreachInternal, tblDependencies01.UESLABreachExternal, tblDependencies01.UECorporatePolicyBreach, tblDependencies01.UEOperatingModelDiscrepancy, tblDependencies01.DefSLABreachInternal, " & _
"tblDependencies01.DefSLABreachExternal , tblDependencies01.DefCorporatePolicyBreach, tblDependencies01.DefOperatingModelDiscrepancy, tblDependencies01.OPSLABreachInternal, tblDependencies01.OPSLABreachExternal, tblDependencies01.OPCorporatePolicyBreach, tblDependencies01.OPOperatingModelDiscrepancy, tblDependencies01.EHSLABreachInternal, tblDependencies01.EHSLABreachExternal, tblDependencies01.EHCorporatePolicyBreach, " & _
"tblDependencies01.EHOperatingModelDiscrepancy , tblDependencies01.DTSLABreachInternal, tblDependencies01.DTSLABreachExternal, tblDependencies01.DTCorporatePolicyBreach, tblDependencies01.DTOperatingModelDiscrepancy, tblDependencies01.ECSLABreachInternal, tblDependencies01.ECSLABreachExternal, tblDependencies01.ECCorporatePolicyBreach, tblDependencies01.ECOperatingModelDiscrepancy " & _
"FROM (tblTeamsDepartments INNER JOIN tblTeams ON tblTeamsDepartments.ID = tblTeams.Department) INNER JOIN (tblValueChain01 INNER JOIN ((tblValueChain03 INNER JOIN tblValueChain02 ON tblValueChain03.IDMacroProcess = tblValueChain02.IDMicroProcesso02) INNER JOIN tblDependencies01 ON tblValueChain03.ID = tblDependencies01.IDSubProcess) ON tblValueChain01.IDMacroProcesso = tblValueChain02.IDMacroProcesso01) ON tblTeams.ID = tblDependencies01.Group WHERE [tblDependencies01].[ID]= '" & ID & "'"
Form_frmValueChainDynamic01.Form.RecordSource = sql_get
Possible typo:
...
INNER JOIN tblValueChain02 ON tblValueChain03.IDMacroProcess = tblValueChain02.IDMicroProcesso02)`
...
...perhaps should be IDMacroProcesso (missing "o" at the end of this field)?
Is [tblDependencies01].[ID] a number field? If so, then in your WHERE clause you've used single quotes denoting you're expecting to match a string; so this:
WHERE [tblDependencies01].[ID]= '" & ID & "'"
...should be written like this, if ID is a number:
WHERE [tblDependencies01].[ID]=" & ID
You've referred to most fields in your SELECT clause using the tableName.fieldName convention except for PotSolution (this may not be an issue, but it's good to be consistent!)
Some more things to try if the above doesn't work: http://allenbrowne.com/subquery-02.html#QueryTooComplex