Results 1 to 5 of 5
  1. #1
    NJK is offline Novice
    Windows 7 64bit Access 2003
    Join Date
    Jul 2015
    Posts
    4

    Turning criteria off when no value is put forward


    I have a query that retrieves contact details and uses values in another form as criteria to filter the results for a report. However I only want it to use criteria if a value is given for that detail.

    For example I want a report to output all contacts from company "xyz" so I have set "xyz" as the company filter on the form. If I have not selected a company in the form I want the query to return all contacts - effectively the filter is switched off.

    How do I do this?

  2. #2
    CJ_London is online now VIP
    Windows 8 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,927
    the basic construct is

    WHERE (Company='" & forms!myform!companyfilter & "' OR " & forms!myform!companyfilter & " is Null)

  3. #3
    NJK is offline Novice
    Windows 7 64bit Access 2003
    Join Date
    Jul 2015
    Posts
    4
    Quote Originally Posted by Ajax View Post
    the basic construct is

    WHERE (Company='" & forms!myform!companyfilter & "' OR " & forms!myform!companyfilter & " is Null)


    sorry still getting anything with a value in or not. To make sure I have interpreted it correctly this is the filter code I entered into the query and why:-

    WHERE (tblContacts.Company='" & Forms![Contact report]!CompanyCombo.value & "' OR " & Forms![Contact report]!CompanyCombo.value & " is Null)



    tbl.Contacts.Company - is the table and field

    Forms![Contact report]!CompanyCombo.value - is the form and value location

    Many thanks

  4. #4
    CJ_London is online now VIP
    Windows 8 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,927
    your interpretation for field/table/control names is correct - but construction is not. My mistake, I mixed two styles. If you are building this in your query then your query will look something like

    SELECT *
    FROM tblContacts
    WHERE (Company= Forms![Contact report]!CompanyCombo OR Forms![Contact report]!CompanyCombo is Null)
    No need to use the .value - that is the default property used


    Also if you are using lookups in your contacts table for the company field, this can cause confusion. Depends on how it is constructed but you may be seeing text but looking up a number

  5. #5
    NJK is offline Novice
    Windows 7 64bit Access 2003
    Join Date
    Jul 2015
    Posts
    4
    Quote Originally Posted by Ajax View Post
    your interpretation for field/table/control names is correct - but construction is not. My mistake, I mixed two styles. If you are building this in your query then your query will look something like

    No need to use the .value - that is the default property used


    Also if you are using lookups in your contacts table for the company field, this can cause confusion. Depends on how it is constructed but you may be seeing text but looking up a number

    Spot on thanks

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

Similar Threads

  1. Replies: 5
    Last Post: 12-14-2014, 05:06 AM
  2. Turning 5% to 95%
    By Gabriel2012 in forum Access
    Replies: 3
    Last Post: 12-06-2012, 12:06 PM
  3. Showing a specific forward date ?
    By Lojik in forum Queries
    Replies: 2
    Last Post: 03-24-2011, 07:38 PM
  4. Bringing forward a data in a form
    By cwwaicw311 in forum Forms
    Replies: 9
    Last Post: 02-24-2010, 07:58 PM
  5. Combo Box - Paging Forward / Back
    By neilrpf in forum Forms
    Replies: 0
    Last Post: 03-01-2006, 05:21 PM

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