Thanks for the reference. But when I tried it with my SQL code, nothing happened whin I clicked the button on the form.
Here is my code...
Private Sub Command8_DblClick(Cancel As Integer)
Dim strName As String
Dim strList As String
Dim strFilterText As String
Dim varItem As Variant
Dim strQuote
Dim strSQL As String
Dim qdf As DAO.QueryDef
Dim dbs As DAO.Database
Set dbs = CurrentDb()
strQuote = Chr$(34)
strList = ""
With Me!lstFY
For Each varItem In .ItemsSelected
strName = strQuote & .Column(0, varItem) & strQuote & ","
strList = strList & strName
Next
strFilterText = Left(strList, Len(strList) - 1)
End With
'[txtList] = strFilterText
strSQL = PARAMETERS Forms![fProjDuration]![lstFY] Text ( 255 );
SELECT DISTINCTROW tProject.BeltName, tProject.ChargeNo, tProject.SigmaPlusNo, tProject.DStart, tProject.DEnd, qTTLCostTTL.PreDHrsTTL, IIf([DEnd] Is Null,DateDiff("d",[DStart],Date()),DateDiff("d",[DStart],[DEnd])) AS DDuration, qTTLCostTTL.DHrsTTL, tProject.MEnd, IIf([MEnd] Is Null,DateDiff("d",[DEnd],Date()),DateDiff("d",[DEnd],[MEnd])) AS MDuration, qTTLCostTTL.MHrsTTL, tProject.AEnd, IIf([AEnd] Is Null,DateDiff("d",[MEnd],Date()),DateDiff("d",[MEnd],[AEnd])) AS ADuration, qTTLCostTTL.AHrsTTL, tProject.IEnd, IIf([IEnd] Is Null,DateDiff("d",[AEnd],Date()),DateDiff("d",[AEnd],[IEnd])) AS IDuration, qTTLCostTTL.IHrsTTL, tProject.CEnd, IIf([CEnd] Is Null,DateDiff("d",[IEnd],Date()),DateDiff("d",[IEnd],[CEnd])) AS CDuration, qTTLCostTTL.CHrsTTL, tProject.REnd, IIf([REnd] Is Null,DateDiff("d",[CEnd],Date()),DateDiff("d",[CEnd],[REnd])) AS RDuration, qTTLCostTTL.RHrsTTL, tProject.[Charge#Status], tProject.SigmaStatus, tProject.RejectDate, tProject.CC, First(tProject.ProjectName) AS [First Of ProjectName], Sum(tP
roject.Estimate) AS [Sum Of Estimate], tProject.FY, IIf([ProjectType] Like 1,"Regular",IIf([ProjectType] Like 2,"Admin",IIf([ProjectType] Like 3,"BeltSupport"))) AS ProjType
strSQL = strSQL & FROM tProject LEFT JOIN qTTLCostTTL ON tProject.ChargeNo = qTTLCostTTL.ChargeNo
strSQL = strSQL & GROUP BY tProject.BeltName, tProject.ChargeNo, tProject.SigmaPlusNo, tProject.DStart, tProject.DEnd, qTTLCostTTL.PreDHrsTTL, IIf([DEnd] Is Null,DateDiff("d",[DStart],Date()),DateDiff("d",[DStart],[DEnd])), qTTLCostTTL.DHrsTTL, tProject.MEnd, IIf([MEnd] Is Null,DateDiff("d",[DEnd],Date()),DateDiff("d",[DEnd],[MEnd])), qTTLCostTTL.MHrsTTL, tProject.AEnd, IIf([AEnd] Is Null,DateDiff("d",[MEnd],Date()),DateDiff("d",[MEnd],[AEnd])), qTTLCostTTL.AHrsTTL, tProject.IEnd, IIf([IEnd] Is Null,DateDiff("d",[AEnd],Date()),DateDiff("d",[AEnd],[IEnd])), qTTLCostTTL.IHrsTTL, tProject.CEnd, IIf([CEnd] Is Null,DateDiff("d",[IEnd],Date()),DateDiff("d",[IEnd],[CEnd])), qTTLCostTTL.CHrsTTL, tProject.REnd, IIf([REnd] Is Null,DateDiff("d",[CEnd],Date()),DateDiff("d",[CEnd],[REnd])), qTTLCostTTL.RHrsTTL, tProject.[Charge#Status], tProject.SigmaStatus, tProject.RejectDate, tProject.CC, tProject.FY, IIf([ProjectType] Like 1,"Regular",IIf([ProjectType] Like 2,"Admin",IIf([ProjectType] Like 3,"BeltSupport")))
strSQL = strSQL & HAVING (((tProject.FY)=[Forms]![fProjDuration]![lstFY] Or [Forms]![fProjDuration]![lstFY] Is Null));
dbs.QueryDefs.Delete "qProjDurationDayHours"
Set qdf = dbs.CreateQueryDef("qProjDurationDayHours", strSQL)
DoCmd.OpenQuery " qProjDurationDayHours"
Set qdf = Nothing
Set dbs = Nothing
End Sub
Here is my SQL on the Query...
PARAMETERS Forms![fProjDuration]![lstFY] Text ( 255 );
SELECT DISTINCTROW tProject.BeltName, tProject.ChargeNo, tProject.SigmaPlusNo, tProject.DStart, tProject.DEnd, qTTLCostTTL.PreDHrsTTL, IIf([DEnd] Is Null,DateDiff("d",[DStart],Date()),DateDiff("d",[DStart],[DEnd])) AS DDuration, qTTLCostTTL.DHrsTTL, tProject.MEnd, IIf([MEnd] Is Null,DateDiff("d",[DEnd],Date()),DateDiff("d",[DEnd],[MEnd])) AS MDuration, qTTLCostTTL.MHrsTTL, tProject.AEnd, IIf([AEnd] Is Null,DateDiff("d",[MEnd],Date()),DateDiff("d",[MEnd],[AEnd])) AS ADuration, qTTLCostTTL.AHrsTTL, tProject.IEnd, IIf([IEnd] Is Null,DateDiff("d",[AEnd],Date()),DateDiff("d",[AEnd],[IEnd])) AS IDuration, qTTLCostTTL.IHrsTTL, tProject.CEnd, IIf([CEnd] Is Null,DateDiff("d",[IEnd],Date()),DateDiff("d",[IEnd],[CEnd])) AS CDuration, qTTLCostTTL.CHrsTTL, tProject.REnd, IIf([REnd] Is Null,DateDiff("d",[CEnd],Date()),DateDiff("d",[CEnd],[REnd])) AS RDuration, qTTLCostTTL.RHrsTTL, tProject.[Charge#Status], tProject.SigmaStatus, tProject.RejectDate, tProject.CC, First(tProject.ProjectName) AS [First Of ProjectName], Sum(tProject.Estimate) AS [Sum Of Estimate], tProject.FY, IIf([ProjectType] Like 1,"Regular",IIf([ProjectType] Like 2,"Admin",IIf([ProjectType] Like 3,"BeltSupport"))) AS ProjType
FROM tProject LEFT JOIN qTTLCostTTL ON tProject.ChargeNo = qTTLCostTTL.ChargeNo
GROUP BY tProject.BeltName, tProject.ChargeNo, tProject.SigmaPlusNo, tProject.DStart, tProject.DEnd, qTTLCostTTL.PreDHrsTTL, IIf([DEnd] Is Null,DateDiff("d",[DStart],Date()),DateDiff("d",[DStart],[DEnd])), qTTLCostTTL.DHrsTTL, tProject.MEnd, IIf([MEnd] Is Null,DateDiff("d",[DEnd],Date()),DateDiff("d",[DEnd],[MEnd])), qTTLCostTTL.MHrsTTL, tProject.AEnd, IIf([AEnd] Is Null,DateDiff("d",[MEnd],Date()),DateDiff("d",[MEnd],[AEnd])), qTTLCostTTL.AHrsTTL, tProject.IEnd, IIf([IEnd] Is Null,DateDiff("d",[AEnd],Date()),DateDiff("d",[AEnd],[IEnd])), qTTLCostTTL.IHrsTTL, tProject.CEnd, IIf([CEnd] Is Null,DateDiff("d",[IEnd],Date()),DateDiff("d",[IEnd],[CEnd])), qTTLCostTTL.CHrsTTL, tProject.REnd, IIf([REnd] Is Null,DateDiff("d",[CEnd],Date()),DateDiff("d",[CEnd],[REnd])), qTTLCostTTL.RHrsTTL, tProject.[Charge#Status], tProject.SigmaStatus, tProject.RejectDate, tProject.CC, tProject.FY, IIf([ProjectType] Like 1,"Regular",IIf([ProjectType] Like 2,"Admin",IIf([ProjectType] Like 3,"BeltSupport")))
HAVING (((tProject.FY)=[Forms]![fProjDuration]![lstFY] Or [Forms]![fProjDuration]![lstFY] Is Null));
Please Please help,
ray: