Results 1 to 13 of 13
  1. #1
    QuantifyRisk is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jul 2014
    Posts
    65

    Split Form that Filters

    I am trying to make a form that resembles a split form. However, I want the boxes at the top to be filters rather than boxes that edit the data (2 combo boxes, 3 type ins). I want the form to show about 5 or so filters and filter the table part as I type (or select). Meaning, I don't wanna type something, hit "Filter" then see if I need to filter some more. At the end, I want to create a button that takes the selcted record from the table and opens it in the original form for ntering data so it can be completed. Is this doable?



    I've been trying to get it to work but I cannto seem to get rid of those text editing boxes and just make them filtering fields.

  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 sql.
    on btnFind_Click()...

    Code:
    dim sSql as string, sWhere as string
    
    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
    sWhere= mid(sWhere,4)
    sSql = "SELECT * FROM tblCompany WHERE " & sWhere
    frmResults.Recordsource = sSql

  3. #3
    QuantifyRisk is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jul 2014
    Posts
    65
    Sorry I'm on a 1 month delay but I haven't touched the database since. I've never done SQL before and, thus, your post might as well be in Russian.

  4. #4
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,930
    Do you mean you've never done VBA? VBA and SQL are not the same. VBA can run SQL statements. Access uses SQL to build query objects. You do build queries in Access? Switch the query builder to SQL View to see the statement. That's how I learned a lot of SQL.

    Also, go to http://www.w3schools.com/sql/default.asp

    Emulating a split form is not easy, that's why Access introduced split form with 2007.

    Can have 'filter' boxes in the header of a split form.
    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
    QuantifyRisk is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jul 2014
    Posts
    65
    I've done some VBA, but it's not something I would say I could write on my own. SQL I have never worked with.
    I'm trying to get this to be as simple as possible for the user where they can search for a record in a split form, select it, and load it in the main form to edit the data.

  6. #6
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,930
    Did you try this with the Split form object?
    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
    QuantifyRisk is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jul 2014
    Posts
    65
    I put in this:

    Dim sSql As String, sWhere As String
    If Not IsNull(Text0) Then sWhere = sWhere & " and [DateEntered]='" & Text0 & "'"
    If Not IsNull(Text4) Then sWhere = sWhere & " and [AgencyName]='" & Text4 & "'"
    If Not IsNull(Text12) Then sWhere = sWhere & " and [Contact]=" & chkContact.Value & "'"
    If Not IsNull(Text20) Then sWhere = sWhere & " and [AgencyType]='" & Text20.Value & "'"
    If Not IsNull(Text28) Then sWhere = sWhere & " and [LicensingRep]=" & Text28.Value
    'remove 1st And
    sWhere = Mid(sWhere, 4)
    sSql = "SELECT * FROM NewAgentChecklist WHERE " & sWhere
    frmResults.RecordSource = sSql

    And it had a problem with the last line. "Object required" error.

  8. #8
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,930
    I prefer to set the form Filter and FilterOn properties. Review http://allenbrowne.com/ser-62code.html
    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.

  9. #9
    QuantifyRisk is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jul 2014
    Posts
    65
    Would it be better to do something like this:
    http://www.access-programmers.co.uk/...d.php?t=188663

    I'm trying it now to see if I can do multiple text boxes to search for things.

  10. #10
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,930
    That approach shows records in a listbox. That is an option but if you just want to filter the form, look at the link I posted.
    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.

  11. #11
    QuantifyRisk is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jul 2014
    Posts
    65
    Ok. I'm using that link you sent earlier. Sorry I missed it the first read through.

    It works great... except for my number field

    I changed it to:
    If Not IsNull(Me.AgencyCode) Then
    strWhere = strWhere & "([AgencyCode] = " & Me.AgencyCode & ") AND "
    End If

    But it never returns a value.

  12. #12
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,930
    It should.

    Have you step debugged?
    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.

  13. #13
    QuantifyRisk is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jul 2014
    Posts
    65
    I was looking at the wrong number... pathetic. Thanks everyone for your help.

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

Similar Threads

  1. Access Form Filters?????
    By Z1nkstar in forum Access
    Replies: 7
    Last Post: 03-14-2014, 02:04 PM
  2. Table to Form Filters
    By icloudy in forum Forms
    Replies: 1
    Last Post: 07-31-2013, 04:45 PM
  3. Filters in one form affecting another...
    By Dominaz in forum Access
    Replies: 1
    Last Post: 10-25-2011, 04:55 PM
  4. Form Filters Help
    By JeffG3209 in forum Forms
    Replies: 1
    Last Post: 05-22-2011, 10:31 PM
  5. Creating Filters on a Form
    By Nixx1401 in forum Access
    Replies: 4
    Last Post: 02-27-2010, 05:32 AM

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