Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.


query and vba question

query and vba question

I have the following code in a report on open event


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")
     'txtdatestart.Value = Format(dteStart, "mm/dd/yyyy")
     'txtdateEnd = dteEnd 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:


=IIf(Left([PermitNo],2)="WH" And (IsNull([RetireDate]) Or [RetireDate]>[txtdateEnd]),"1",
IIf(Left([PermitNo],2)<>"WH" And (IsNull([RetireDate]) Or [RetireDate]>[txtdateEnd]),"2",
IIf(Left([PermitNo],2)="WH" ,"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
the problem is that I need to have all

RE: query and vba question

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".

Hook'D on Access
MS Access MVP

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!


Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close