I'm not sure is you are having problems because of the missing space as per June7 or you are having problems if one or both of the combo boxes are empty/NULL.
Is the inline SQL in a form module or a standard module?
Are the values in the combo boxes numbers, text or dates? If Text or Dates, they need to be delimited.
Here is an example of how I would write the code
Code:
Option Compare Database 'these two lines should be at the top of EVERY module - form or standard
Option Explicit 'these two lines should be at the top of EVERY module - form or standard
Private Sub Command3_Click()
Dim TSQL As String
Dim tmpWHERE As String
'generate basic SQL string
TSQL = "SELECT DPWProgramCostStatus.DatePrepared, DPWProgramCostStatus.SubmittedFHWA, DPWProgramCostStatus.FHWAEffective,"
TSQL = TSQL & " DPWProgramCostStatus.FY, DPWProgramCostStatus.PendingApproval, DPWProgramCostStatus.ProjectNumber, DPWProgramCostStatus.ProjectTitle,"
TSQL = TSQL & " DPWProgramCostStatus.[1240ModNo], DPWProgramCostStatus.FinalVoucher, DPWProgramCostStatus.TOTAL,"
TSQL = TSQL & " DPWProgramCostStatus.NATLHWYSYSTERRITORIESSTEA3HT 10, DPWProgramCostStatus.NHSTERRITORIESSLUEXTLT1E,"
TSQL = TSQL & " DPWProgramCostStatus.NHSTERRITORIESFY06LT10, DPWProgramCostStatus.PRTERRITORIALHWYSMAP21MT10,"
TSQL = TSQL & " DPWProgramCostStatus.PRTERRITORIALHWYSMAP21EXTMT1E , DPWProgramCostStatus.NATLHWYSYSTERRITORIESTEA21QT10,"
TSQL = TSQL & " DPWProgramCostStatus.PRTERRITORIALHWYSFMISZT10, DPWProgramCostStatus.BRIDGEREPLACREHABDISCH060,"
TSQL = TSQL & " DPWProgramCostStatus.HIGHWAYINFRATERRITORIESZ160, DPWProgramCostStatus.FY19HIGHWAYINFRASTRUCTUREPROG RAMSZ169,"
TSQL = TSQL & " DPWProgramCostStatus.TRANSPORTATIONIMPPROJLY30, DPWProgramCostStatus.ER2004HURRICANESADDLFUND09J0,"
TSQL = TSQL & " DPWProgramCostStatus.EMERRELIEFFEDAIDOTHER09V0, DPWProgramCostStatus.FY17OJTSSZ49A, DPWProgramCostStatus.FY17NSTIAllocationZ49B,"
TSQL = TSQL & " DPWProgramCostStatus.FY16NSTIAllocationZ49S, DPWProgramCostStatus.FY17DARFUNDS74YF, DPWProgramCostStatus.NAVYCONSTLANDACQPROJ73P0,"
TSQL = TSQL & " DPWProgramCostStatus.MILITARYCONSTRNAVYFY101473V0, DPWProgramCostStatus.GUAMIMPACTSTUDYUSMC24C0,"
TSQL = TSQL & " DPWProgramCostStatus.WILDLIFEREFUGEROADSTEA214190 , DPWProgramCostStatus.Notes"
TSQL = TSQL & " FROM DPWProgramCostStatus"
'determine where clause
tmpWHERE = " WHERE"
If Len(Trim([Forms]![FedAidStatusQueryFYSelection]![FYComBo]) & "") > 0 Then
tmpWHERE = tmpWHERE & " DPWProgramCostStatus.FY = " & [Forms]![FedAidStatusQueryFYSelection]![FYComBo] & " AND"
End If
If Len(Trim([Forms]![FedAidStatusQueryFYSelection]![PendAppComBo]) & "") > 0 Then
tmpWHERE = tmpWHERE & " DPWProgramCostStatus.PendingApproval = " & [Forms]![FedAidStatusQueryFYSelection]![PendAppComBo]
End If
'check for " and" at the end of where string - if found remove it
If Len(Trim(tmpWHERE & "")) > 0 Then
If Right(tmpWHERE, 4) = " AND" Then
tmpWHERE = Left(tmpWHERE, Len(tmpWHERE) - 4)
End If
End If
'add the where clause, if any
If Len(Trim(tmpWHERE)) > 6 Then
TSQL = TSQL & tmpWHERE
End If
Debug.Print TSQL
End Sub