Dear mykebass,
Several things:
1) If I remember correctly from my past battles, iif() funtion does not work in Criteria.
So, I would place your test of parameter fields in vba code on your form and place the result in a hidden field on the form and use that hidden form as your criteria.
Second, if dates are null, then you want all records, so instead of the '*', just leave criteria blank
Define Me.HiddenChoice
IF IsNull(Me.txtbegdate) or IsNull(txtenddate) Then
Me.HiddenChoice = ""
else
Me.HiddenChoice = "between #" & Me.txtbegdate & "# and #" & Me.txtenddate & "#"
end if
Then use [Forms]![frmMain]![HiddenChoice]
as your criteria in your Query.
To Correct the Statement
IIf(IsNull([Forms]![frmMain]![txtbegdate]-[Forms]![frmMain]![txtenddate]),*,between [Forms]![frmMain]![txtbegdate] and Forms![frmMain]![txtenddate] )
Try this, but I do not like the '*' in either case
iif(Len(Trim$([Forms]![frmMain]![txtbegdate] & [Forms]![frmMain]![txtenddate] & " "))=0," Like *","between #" & [Forms]![frmMain]![txtbegdate] & "# and #" & Forms![frmMain]![txtenddate] & "#" )
or
iif(Len(Trim$([Forms]![frmMain]![txtbegdate] & [Forms]![frmMain]![txtenddate] & " "))=0,"","between #" & [Forms]![frmMain]![txtbegdate] & "# and #" & Forms![frmMain]![txtenddate] & "#" )
Hope This Helps,
Hap
Access Developer
Access based Add-on Solutions
Access Consultants forum