I have a form where a user enters three search criteria (or less if they like). When they are finished a sub-form displays the results. I want to give the user the option to export those results into Excel. I am trying to get a query to display results based on the user's search criteria. I need to write a SQL statement that will filter (on the query) based on the text box value if the user has entered a criteria. Otherwise I want to display all for that field. I have included my attempt below, but this doesn't work.
Code:
SELECT VEND_GARN.EntityType AS [Entity Type], VEND_GARN.TP_SSN AS [TP SSN], VEND_GARN.AcctID AS [Account ID], VEND_GARN.TPName AS [TP Name], VEND_GARN.AcctType AS [Acount Type], VEND_GARN.BegPd AS [Period Begin], VEND_GARN.EndPd AS [Period End], VEND_GARN.TaxDue AS Tax, VEND_GARN.PenDue AS Penalty, VEND_GARN.IntDue AS Interest, VEND_GARN.TotDue AS [Total Liab], VEND_GARN.ReqGarnAmt AS [Garn Amount], AgencyFID.EntityName AS [Agency Name], VEND_GARN.FileDate AS [Garnish Date], VEND_GARN.FunctCode AS [Function Code], VEND_GARN.BudgetCode AS [Budget Code], VEND_GARN.FundCode AS [Fund Code]
FROM VEND_GARN INNER JOIN AgencyFID ON VEND_GARN.AgencyFID = AgencyFID.EntityFID
WHERE (((VEND_GARN.FunctCode)=IIf([Forms]![frmVGLookup]![txtFunctCode]<>"",[Forms]![frmVGLookup]![txtFunctCode],[FunctCode])) AND ((VEND_GARN.BudgetCode)=IIf([Forms]![frmVGLookup]![txtBudgetCode]<>"",[Forms]![frmVGLookup]![txtBudgetCode],[BudgetCode])) AND ((VEND_GARN.FundCode)=IIf([Forms]![frmVGLookup]![txtFundCode]<>"",[Forms]![frmVGLookup]![txtFundCode],[FundCode])));
Thanks for your help in advance.