Results 1 to 2 of 2
  1. #1
    shaun_za is offline Novice
    Windows 8 Access 2013
    Join Date
    Aug 2015
    Posts
    8

    Query Criteria not including null values


    Hi, I have a form that has multiple textboxes in which the criteria for my query is typed into. However, any records containing null values are excluded if there is nothing in the textbox.

    Criteria : Like "*" & [Forms]![Formname]![Textboxname] & "*"

    Thank you!

  2. #2
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,525
    You cant use form boxes in a query if there's nothing in them..so..
    Test all controls for a possible filter then build the where clause.


    Code:
    if not isnull(cboState) then   sWhere = sWhere & " and [state]='" & cboState & "'"
    if not IsNull(txtName) then    sWhere = sWhere & " and [Name]='" & txtName & "'"
    if not IsNull(chkContact) then sWhere = sWhere & " and [Contact]=" & chkContact.value
    
        'remove 1st And
    if len(sWhere)>0 then sWhere= mid(sWhere,5)
    
      'just use the filter
    iLen = Len(sWhere) - 5
    If iLen <= 0 Then
        me.filterOn = false
    Else
        me.filter = sWhere
        me.filterOn = true
    End If
    'OR
    'apply the sql to the form

    sSql = "SELECT * FROM tblCompany WHERE " & sWhere

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

Similar Threads

  1. Replies: 7
    Last Post: 04-02-2015, 07:25 AM
  2. Replies: 5
    Last Post: 11-30-2014, 08:12 PM
  3. Query criteria with values and null
    By robsworld78 in forum Queries
    Replies: 13
    Last Post: 03-27-2012, 05:44 AM
  4. Replies: 1
    Last Post: 02-23-2012, 02:27 PM
  5. Query including Null relationship?
    By David Criniti in forum Database Design
    Replies: 0
    Last Post: 08-14-2009, 09:10 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