473,407 Members | 2,359 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,407 software developers and data experts.

Using IIF in Query Criteria based on Option Group

I have an option group (TimeFrameOption) with three options: All, Last 6 months, and Last 12 Months. When an option is selected, I want to query dates in a listbox (CallReport) to display all dates (I used Date() - 9999999999 days for all), dates within the last six months, or dates within the last year.

I placed this formula in the criteria in the SQL query builder for the listbox.

IIf([timeframeoption]=1,[CallReport].[Date] Between Date()-9999999999 And Date(),IIf([timeframeoption]=2,[CallReport].[Date] Between Date()-180 And Date(),([CallReport].[Date]) Between Date()-365 And Date()))

I used only the between and statements and Access added [CallReport].[Date] to the syntax.

I tested the date formulas invididually and they all work fine outside of the IIF statement. For instance, Between Date() and Date() -180 shows all records for the last 6 months.

Any suggestions on the syntax of the IIF statement?

Thanks,
Jason
May 14 '10 #1
5 6686
patjones
931 Expert 512MB
So, are you saying that one of the columns in the listbox contains the date, and you want to narrow down the items that appear in the listbox based upon what the user selects in the option group? If this is the case what are you using as the record source for the listbox?

Pat
May 14 '10 #2
Jim Doherty
897 Expert 512MB
@hbaf208
Reconsider the logic sequence Jason instead of using an IIIF formula (which looks unwieldy and tiresome) Change it to the AfterUpdate event for the option group so that, whatever changes are made in the option group will populate the listbox commensurate with the value selected in the option group 1,2,or 3

The VBA code for the Afterupdate event will look like this

Expand|Select|Wrap|Line Numbers
  1. 'First set the main portion of SQL to satisfy a consistent dataset
  2. 'for the listbox
  3. Dim MySQL as String
  4. Dim MyCriteria as String
  5. MySQL = "SELECT FieldName1,FieldName2 FROM YourTableName WHERE " & MyCriteria
  6.  
  7. Select Case Me!TimeFrameOption
  8. Case is = 1
  9. MyCriteria="[CallReport].[Date] Between Date()-9999999999 And Date()"
  10. Case is = 2
  11. MyCriteria = "[CallReport].[Date] Between Date()-180 And Date()"
  12. Case is = 3
  13. MyCriteria = "[CallReport].[Date]) Between Date()-365 And Date()"
  14. End Select
  15.  
  16. Me!YourListboxName.rowsource=MySQL & MyCriteria
  17.  
  18.  
As you can see you can keep adding extra bits to this Select Case code should you need to add more elements to your option group frame and not
continually be confused wondering if something falls correctly on the side of a True/False IFF statement.

I dont know how familar you are with VBA but the above method is a much better way of handling this type of listbox population. As you can see the SQL to support the rowsource property is built on the fly and passed to the rowsource of the listbox at runtime only after someone selects a value from the option group.
May 14 '10 #3
Jim Doherty
897 Expert 512MB
@zepphead80
Whoops sorry Pat, didnt see you there obviously in at same time as me :-)
May 14 '10 #4
patjones
931 Expert 512MB
@Jim Doherty
Don't worry about it...I was going to suggest something similar to you but wanted to make sure I understood what the OP was trying to do with the listbox.
May 14 '10 #5
Worked very well after I added the other criteria to the SQL statement that I had in the query builder. If someone else uses this code, they will want to remove the ) in Case 3 after [CallReport].[Date].

I very much appreciate the assistance.

Thanks,
Jason
May 14 '10 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: neptune | last post by:
I have a query where each customer has an or . Sometimes both fields for a customer are populated, but if is null, then will be populated and vice versa. I have a form, , where I select a...
2
by: Steve | last post by:
Access 97. I have a form where there is an option group with two buttons, and a combo box. The combo box Row Source is a query. The option group has two options a) include a subset of the...
7
by: keliie | last post by:
Hello Just a quick question that I've spent a few hours trying to solve with no luck (although one would think this should be fairly easy). I have a form with a subform. The subform is based...
7
by: Triple7 | last post by:
Hi there, basically what I am trying to do (without using code as I don’t know how to do that with a code) is to retrieve the previous 5 days & the next 5 days (date wise)against a query1 that...
5
by: jslssuze | last post by:
I have medium experience with Access but need help trying to create a query for the following scenario... any and all help will be greatly appreciated! A user will select different items on an...
2
by: shreyasi | last post by:
i create a page..there i use check box..how can i call perticular quary from mysql using the check box.i want if i select a checkbox and submit the form then the corrosponding record will be...
2
by: cmartin1986 | last post by:
First of all I want to thank all of you that have helped me in the past this is an awesome fourm. My problem today is I have a database that builds charts that are viewed by a large group every...
1
by: pipestew | last post by:
I have a form which allows me to enter a value and then view a report based on that value. The value is currently entered as P-##### and the query criteria is... !! I want the Form to have...
3
by: BarbaraB | last post by:
Is there anyway of returning the value of an option group (in access 2003) back to what it was before any entry was made? I frequenty find people are wishing to remove there answer but with an...
9
ajhayes
by: ajhayes | last post by:
Hello everyone, This is my first time posting here and I'm hoping someone can help me out. I'm a relative newbie to Access and am pretty much learning as I go along, so please bear with me. ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.