Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

query and vba question

Status
Not open for further replies.

Lhuffst

Programmer
Jun 23, 2003
503
US
I have the following code in a report on open event
Code:
 strTemp = InputBox("Enter Start Date Range:", "Start Date", dteStart)
    If IsDate(strTemp) Then dteStart = CDate(strTemp)
    strTemp = InputBox("Enter End Date Range:", "End Date", Format(dteEnd, "mm/dd/yyyy"))
    If IsDate(strTemp) Then dteEnd = CDate(strTemp)
 
    lblreportdates.Caption = Format(dteStart, "mm/dd/yyyy") & " - " & Format(dteEnd, "mm/dd/yyyy")
     [highlight #AD7FA8]'txtdatestart.Value = Format(dteStart, "mm/dd/yyyy")
     'txtdateEnd = dteEnd[/highlight] These were unbound text boxes on report so I could pass the date info but says I cannot assign a value to the object.

strFilter = strFilter & "(  [retireDate] > #" & dteEnd & "# AND [effectiveDate] Between #" & dteStart & "# AND #" & dteEnd & "# )"
strFilter = strFilter & " OR "
strFilter = strFilter & "(  [effectiveDate] < #" & dteStart & "#  AND [RetireDate] Between #" & dteStart & "# AND #" & dteEnd & "# )"
strFilter = strFilter & " OR "
strFilter = strFilter & "( isNull( [retireDate]) AND [EffectiveDate] Between #" & dteStart & "# AND #" & dteEnd & "# )"
strFilter = strFilter & " OR "
strFilter = strFilter & "(  [retireDate]  Between #" & dteStart & "# AND #" & dteEnd & "#  AND [effectiveDate] Between #" & dteStart & "# AND #" & dteEnd & "# )"

I'm getting all the correct data but now need to sort the report.
This is what I have so far (columns were separated just for readibility. they are actually in a continuous line:
Code:
=IIf(Left([PermitNo],2)="WH" And (IsNull([RetireDate]) Or [RetireDate]>[txtdateEnd]),"1",
IIf(Left([PermitNo],2)<>"WH" And (IsNull([RetireDate]) Or [RetireDate]>[txtdateEnd]),"2",
[b]IIf(Left([PermitNo],2)="WH"[/b] ,"3","4")))
The bolded portion really needs to say IIf(Left([PermitNo],2)="WH" And ([RetireDate] Between [txtdatestart] And [txtdateEnd]) Or [RetireDate]<[txtdatestart],"3","4"

When I build it one piece at a time, it works but when I put it together I get an error saying I have to many characters or am missing a } or |.
I think a better method may be to put the input prompt in the query but I wasn't sure if I could do the declarations in code and then just the input prompt statements in the query. What is the order of evaluation between queries and events? Any ideas will be most appreciated.
the sort (1-4) is simply to order the records
1-Active Wastehaulers
2-Active buses/other
3-retired wastehaulers
4-retired buses/other

Thanks in advance
lhuffst
the problem is that I need to have all
 
I think you are going about this wrong. IMO, don't ever use InputBox or parameter prompts in queries. I would first open a form for the user to select the date values. Then open the report from the form.

In addition, I would not use a complex expression with multiple IIf()s. This is a standard business calculation. Consider creating a small user-defined function with arguments of the permit number, retire date, and end date. Save the function in a module named "modBusinessCalcs".

Duane
Hook'D on Access
MS Access MVP
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top