Here's another route you can take. This allows the user to select no criteria, some criteria, or all criteria. It offers more flexibility Below is the basic syntax that you would use.
Code:
Dim strDesc As String
Dim strCity As String
Dim strSalesDate As String
Dim strPropSize As String
strSQL = ""
If Len(Me.cmbLandBldgProp) > 0 Then
If Len(strSQL) > 0 Then
strSQL = strSQL & " AND " & "[Land_Bldg_Desc] in (""" & Me.cmbLandBldgProp & """) "
Else
strSQL = "[Land_Bldg_Desc] in (""" & Me.cmbLandBldgProp & """) "
End If
End If
If Len(Me.cmbCityCat) > 0 Then
If Len(strSQL) > 0 Then
strSQL = strSQL & " AND " & "[City] in (""" & Me.cmbCityCat & """) "
Else
strSQL = "[City] in (""" & Me.cmbCityCat & """) "
End If
End If
If Len(Me.txtDateFrom) > 0 Then
If Len(strSQL) > 0 Then
strSQL = strSQL & " AND " & "[Sales_Date] Between #" & Me.txtDateFrom & "# and #" & Me.txtDateTo & "# "
Else
strSQL = "[Sales_Date] Between #" & "[Sales_Date] Between #" & Me.txtDateFrom & "# and #" & Me.txtDateTo & "# "
End If
End If
If Len(Me.txtAcFrom) > 0 Then
If Len(strSQL) > 0 Then
strSQL = strSQL & " AND " & "[Prop_Size_Ac] Between " & Me.txtAcFrom & " and " & Me.txtAcTo & " "
Else
strSQL = "[Prop_Size_Ac] Between " & Me.txtAcFrom & " and " & Me.txtAcTo & " "
End If
End If
If Len(strSQL) > 0 Then
strSQL = Left(strSQL, Len(strSQL) - 1)
DoCmd.OpenReport "MyReport", acPreview, , strSQL
Else
DoCmd.OpenReport "MyReport", acPreview
End If
Originally Posted by
grad2009
i wrote the folloing
Code:
DoCmd.OpenReport "customer_account", acViewPreview, , "[nam]='" & Me.Combo4 & "' AND #&Cdate(fdate)&# < #Cdate(dat)# AND #&Cdate(ldate)&# > #Cdate(dat)#"
an error occur as in the attachment