I don't think u can do it within the Query (SQL). My approach was to create a function that returned the SQL String based on if and how the (2) date fields were filled. I build an SQL String then Execute it.
(4) Possible Conditions.
...
Dim lcSQL as String
Dim lcWhere as String
Dim ThisDB as DAO.Database
lcSQL = "SELECT f1,f2 FROM table WHERE "
Set ThisDB = CurrentDB
...
'Optional Dates - Build SQL Statement
If IsNull(Me.txtStartdate.VALUE) And IsNull(Me.txtEnddate.VALUE) Then
' No Code Changes Needed!
ElseIf IsNull(Me.txtStartdate.VALUE) = False And IsNull(Me.txtEnddate.VALUE) Then
lcWhere = lcWhere & " AND " & "(CourseStartDate >= #" & Me.txtStartdate.VALUE & "#)"
ElseIf IsNull(Me.txtStartdate.VALUE) And IsNull(Me.txtEnddate.VALUE) = False Then
lcWhere = lcWhere & " AND " & "(CourseStartDate <= #" & Me.txtEnddate.VALUE & "#)"
ElseIf IsNull(Me.txtStartdate.VALUE) = False And IsNull(Me.txtEnddate.VALUE) = False Then
lcWhere = lcWhere & " AND " & "(CourseStartDate >= #" & Me.txtStartdate.VALUE & "# AND " & "CourseStartDate <= #" & Me.txtEnddate.VALUE & "#)"
End If
lcSQL = lcSQL & lcWhere
...
ThisDB.EXECUTE lcSQL, DbOnError...
Steve Medvid
"IT Consultant & Web Master"
e-Mail: Stephen_Medvid@GMACM.com
Chester County, PA Residents
Please Show Your Support...