Results 1 to 10 of 10
  1. #1
    rhewitt is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Sep 2012
    Posts
    74

    Form to dynamically run query with 'OR' clause


    I have a form that supplies a value to a query that runs a report. In some cases, the user would want to add more than one value to the query. I've added checkboxes that supply an extra combobox for the user to add to the query. In the background the query is formed with an 'OR'.
    Click image for larger version. 

Name:	OneValue.png 
Views:	2 
Size:	11.5 KB 
ID:	9642 vs. Click image for larger version. 

Name:	2Values.png 
Views:	2 
Size:	11.3 KB 
ID:	9643

    The problem is I need to be able to show if there is more than one value displayed on the report. My current solution only shows the second value. Is there a way to show both somehow?
    Click image for larger version. 

Name:	Report.png 
Views:	4 
Size:	14.6 KB 
ID:	9644

  2. #2
    June7's Avatar
    June7 is online now VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    For one way to select multiple criteria on one field, review http://allenbrowne.com/ser-50.html

    You want each Cooperative to show on separate page of report?

    If you need more assistance, fastest and easiest way to resolve would be to provide db so can review code, query, report design.

    If you want to provide db, follow instructions at bottom of my post. Identify the objects involved in issue.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    rhewitt is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Sep 2012
    Posts
    74
    AtRiskSpeciesFinderSept26.zip

    My current plan of attack was just to show the names of the cooperative at the top of the report. I can see how separating them onto their own pages could be useful, but then they could just run the query more than once and get the same result.

  4. #4
    June7's Avatar
    June7 is online now VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    Do you want to allow only 3 cooperatives to be selected with the 3 comboboxes? A textbox on report could refer to the three comboboxes and concatenate.

    =forms!formname!combobox1 & ", " & forms!formname!combobox2 & ", " & forms!formname!combobox3

    Yes, user could run query many times to get output for each cooperative but if you could run query and get all printed in one request, isn't that more efficient?
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  5. #5
    rhewitt is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Sep 2012
    Posts
    74
    Yes you're right it would be more efficient. Does this method allow for conditional statements to test if the boxes are empty?

    If cboLCC2 == "" Then
    'Don't concatenate

    My experience with scripting is mostly limited to Python and I've still a newbie when it comes to Access. Your help has been amazing, thank you.

  6. #6
    June7's Avatar
    June7 is online now VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    Conditional inclusion of comma would use IIf and get long and complicated. Consider:

    a = forms!formname!combobox1
    b = forms!formname!combobox2
    c = forms!formname!combobox3

    = a & IIf(IsNull(b) And IsNull(c), "", IIf(Not IsNull(a), ", ", "")) & b & IIf(IsNull(c), "", IIf(Not IsNull(b), ", ", "")) & c

    Put the combobox name references in place of the respective letter variables.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  7. #7
    rhewitt is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Sep 2012
    Posts
    74
    Thanks, WOW, that's quite an expression.

    Seems as if with the substitution of combobox references for letter variables I've gone over the length limit for the expression. I'll have to think of a work around -- I'm sure the IIf IsNull will certainly come in handy.

  8. #8
    rhewitt is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Sep 2012
    Posts
    74
    Ok here's my hacked solution...

    I've concatenated the combobox references with carriage returns, and set the text box property 'Can Grow' to true. Now if more than one box is checked, the cooperatives are listed vertically (not ideal, but close enough).
    Code:
    =[Forms]![FormName]![cbo] & Chr(13) & Chr(10) & [Forms]![FormName]![cbo2] & Chr(13) & Chr(10) & [Forms]![FormName]![cbo3]
    The problem I had here was that the Page Header wouldn't grow with the growing textbox. For reasons I may never understand, the Page Header has no Property "Can Grow." The solution is to create a new arbitrary Group Header, which does support the Can Grow Property.

    New problem! If a user checks queries based on 2 or more cooperatives, then reverts back to one -- the names of the 2nd or 3rd cooperatives are still shown in the report. I need to to do a conditional on the checkboxes. I keep getting back an error that I have the wrong number of arguments.

    Code:
    =[Forms]![SpeciesByLCC]![cboLCC] & IIf([Forms]![SpeciesByLCC]![check1]) Then Chr(13) + Chr(10) & [Forms]![SpeciesByLCC]![cboLCC2]
    Thanks!
    Roy

  9. #9
    June7's Avatar
    June7 is online now VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    There is no 'Then' in an IIf function, just commas. Use ampersand for all concatenation operations. An IIf has 3 arguments:

    IIf(condition, result if true, result if false)

    Try:

    =[Forms]![SpeciesByLCC]![cboLCC] & IIf([Forms]![SpeciesByLCC]![check1], Chr(13) & Chr(10) & [Forms]![SpeciesByLCC]![cboLCC2], "")
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  10. #10
    rhewitt is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Sep 2012
    Posts
    74
    Works beautifully!

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Dynamically linking an Access Query to MS Word
    By delta9857 in forum Import/Export Data
    Replies: 2
    Last Post: 04-23-2012, 07:41 PM
  2. Replies: 7
    Last Post: 03-27-2012, 09:51 AM
  3. Form with Label captions that size dynamically
    By karmacable in forum Forms
    Replies: 3
    Last Post: 09-26-2011, 10:09 PM
  4. Replies: 2
    Last Post: 06-01-2011, 09:32 AM
  5. Replies: 1
    Last Post: 07-17-2006, 06:30 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums