Page 3 of 3 FirstFirst 123
Results 31 to 43 of 43
  1. #31
    Gina Maylone is offline Always learning
    Windows 7 64bit Access 2013
    Join Date
    Jun 2013
    Location
    Afton, MN
    Posts
    544
    I've been monkeying with this all day today, the code I have behind Command230 now is:
    Code:
    Private Sub Command230_Click()
    'Purpose:   This module illustrates how to create a search form, _
                where the user can enter as many or few criteria as they wish, _
                and results are shown one per line.
    'Note:      Only records matching ALL of the criteria are returned.
    'Author:    Allen Browne (allen@allenbrowne.com), June 2006.
    'Option Compare Database
    'Option Explicit
        'Purpose:   Build up the criteria string form the non-blank search boxes, and apply to the form's Filter.
        'Notes:     1. We tack " AND " on the end of each condition so you can easily add more search boxes; _
                        we remove the trailing " AND " at the end.
        '           2. The date range works like this: _
                            Both dates      = only dates between (both inclusive. _
                            Start date only = all dates from this one onwards; _
                            End date only   = all dates up to (and including this one).
        Dim strWhere As String                  'The criteria string.
        Dim lngLen As Long                      'Length of the criteria string to append to.
        Const conJetDate = "\#mm\/dd\/yyyy\#"   'The format expected for dates in a JET query string.
        '***********************************************************************
        'Look at each search box, and build up the criteria string from the non-blank ones.
        '***********************************************************************
        'Text field example. Use quotes around the value in the string.
        If Not IsNull(Me.statusfilter) Then
            strWhere = strWhere & "( [Forms]![contacts]![bidsheet].[Form]![status] = """ & Me.statusfilter & """) AND "
        End If
    '    Another text field example. Use Like to find anywhere in the field.
         If Not IsNull(Me.bidderfilter) Then
            strWhere = strWhere & "( [Forms]![contacts]![bidsheet].[Form]![bidder] = """ & Me.bidderfilter & """) AND "
        End If
        If Not IsNull(Me.biddatefilter) Then
            strWhere = strWhere & "( [Forms]![contacts]![bidsheet].[Form]![biddate] = " & Format(Me.biddatefilter, conJetDate) & ") AND "
        End If
        
        '***********************************************************************
        'Chop off the trailing " AND ", and use the string as the form's Filter.
        '***********************************************************************
        'See if the string has more than 5 characters (a trailng " AND ") to remove.
        lngLen = Len(strWhere) - 5
        If lngLen <= 0 Then     'Nah: there was nothing in the string.
            MsgBox "No criteria", vbInformation, "Nothing to do."
        Else                    'Yep: there is something there, so remove the " AND " at the end.
            strWhere = Left$(strWhere, lngLen)
            'For debugging, remove the leading quote on the next line. Prints to Immediate Window (Ctrl+G).
            'Debug.Print strWhere
            'Finally, apply the string as the form's Filter.
            Me.bidsheet.Form.Filter = strWhere
            Me.bidsheet.Form.FilterOn = True
        
        
        End If
        Debug.Print strWhere
        
    End Sub


  2. #32
    Gina Maylone is offline Always learning
    Windows 7 64bit Access 2013
    Join Date
    Jun 2013
    Location
    Afton, MN
    Posts
    544
    I've played with this all day today. The code behind Command230 is now:
    Code:
    Private Sub Command230_Click()
    'Purpose:   This module illustrates how to create a search form, _
                where the user can enter as many or few criteria as they wish, _
                and results are shown one per line.
    'Note:      Only records matching ALL of the criteria are returned.
    'Author:    Allen Browne (allen@allenbrowne.com), June 2006.
    'Option Compare Database
    'Option Explicit
        'Purpose:   Build up the criteria string form the non-blank search boxes, and apply to the form's Filter.
        'Notes:     1. We tack " AND " on the end of each condition so you can easily add more search boxes; _
                        we remove the trailing " AND " at the end.
        '           2. The date range works like this: _
                            Both dates      = only dates between (both inclusive. _
                            Start date only = all dates from this one onwards; _
                            End date only   = all dates up to (and including this one).
        Dim strWhere As String                  'The criteria string.
        Dim lngLen As Long                      'Length of the criteria string to append to.
        Const conJetDate = "\#mm\/dd\/yyyy\#"   'The format expected for dates in a JET query string.
        '***********************************************************************
        'Look at each search box, and build up the criteria string from the non-blank ones.
        '***********************************************************************
        'Text field example. Use quotes around the value in the string.
        If Not IsNull(Me.statusfilter) Then
            strWhere = strWhere & "( [Forms]![contacts]![bidsheet].[Form]![status] = """ & Me.statusfilter & """) AND "
        End If
    '    Another text field example. Use Like to find anywhere in the field.
         If Not IsNull(Me.bidderfilter) Then
            strWhere = strWhere & "( [Forms]![contacts]![bidsheet].[Form]![bidder] = """ & Me.bidderfilter & """) AND "
        End If
        If Not IsNull(Me.biddatefilter) Then
            strWhere = strWhere & "( [Forms]![contacts]![bidsheet].[Form]![biddate] = " & Format(Me.biddatefilter, conJetDate) & ") AND "
        End If
        
        '***********************************************************************
        'Chop off the trailing " AND ", and use the string as the form's Filter.
        '***********************************************************************
        'See if the string has more than 5 characters (a trailng " AND ") to remove.
        lngLen = Len(strWhere) - 5
        If lngLen <= 0 Then     'Nah: there was nothing in the string.
            MsgBox "No criteria", vbInformation, "Nothing to do."
        Else                    'Yep: there is something there, so remove the " AND " at the end.
            strWhere = Left$(strWhere, lngLen)
            'For debugging, remove the leading quote on the next line. Prints to Immediate Window (Ctrl+G).
            'Debug.Print strWhere
            'Finally, apply the string as the form's Filter.
            Me.bidsheet.Form.Filter = strWhere
            Me.bidsheet.Form.FilterOn = True
        
        
        End If
        Debug.Print strWhere
        
    End Sub
    by Allen Browne.

  3. #33
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,771
    Access saves filter criteria when the form closes. Since FilterOnLoad is set to Yes, the form is filtered when opened. Suggest setting FilterOnLoad to No.

    Me.bidsheet.Form.Filter = strWhere
    Me.bidsheet.Form.FilterOn = True

    Makes no sense to reference the full form path to the subform field, so change to:

    Code:
        If Not IsNull(Me.statusfilter) Then
            strWhere = strWhere & "([status] = """ & Me.statusfilter & """) AND "
        End If
        If Not IsNull(Me.bidderfilter) Then
            strWhere = strWhere & "([bidder] = """ & Me.bidderfilter & """) AND "
        End If
        If Not IsNull(Me.biddatefilter) Then
            strWhere = strWhere & "([biddate] = " & Format(Me.biddatefilter, conJetDate) & ") AND "
        End If
    However, bidder John Doe has 3 Pending records. Why only 1 retrieved by subform? Because John Doe is associated with 3 different ContactIDs in BID table. Only the ContactID 5 BID record can display in subform.
    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.

  4. #34
    Gina Maylone is offline Always learning
    Windows 7 64bit Access 2013
    Join Date
    Jun 2013
    Location
    Afton, MN
    Posts
    544
    I don't know. Does the same thing with the biddate of 10/26.

  5. #35
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,771
    I probably edited previous post while you were reading. I answered my own question.
    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.

  6. #36
    ssanfu is offline Master of Nothing
    Windows XP Access 2010 32bit
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    PMFJI,

    @Gina, I looked at your dB and I have a couple of comments.

    * The first two lines of EVERY code module (standard & Form/Report) should be
    Code:
    Option Compare Database
    Option Explicit
    There are some undefined variables in the code that will cause you problems. (Code won't compile)
    In the IDE, click on TOOLS/OPTIONS. On the Editor tab, check "Require Variable Declaration". (This will add OPTION EXPLICIT to NEW modules.)


    * Take the time to properly name objects.
    Which is easier to know/understand the purpose:
    Command230_Click
    or
    cmdSearch_Click

    What is "Command981_Click"?
    What if it was named "cmdGoToFirst_Click"?




    And for good measure, I'll add:

    * Object names should be only letters, numbers and/or the underscore. NO spaces, punctuation or special characters.




    I'm just sayin.........

  7. #37
    Gina Maylone is offline Always learning
    Windows 7 64bit Access 2013
    Join Date
    Jun 2013
    Location
    Afton, MN
    Posts
    544
    Thanks Steve - I have no problem with anyone jumping in! I'm not sure which control you are referring to that has a space. I usually don't use spaces. I DO get a little lazy with buttons, point taken. And for the record, my code does compile! That's what is driving me nuts, but again, point taken. Thank you for jumping in :-)!

  8. #38
    Gina Maylone is offline Always learning
    Windows 7 64bit Access 2013
    Join Date
    Jun 2013
    Location
    Afton, MN
    Posts
    544
    Good morning all, again thank you for taking the time to help me muddle through this and I apologize if I wasn't clear from the beginning. Just to clarify a few things, what I'm trying to get Access to do is basically opposite of what it's set up to do...Contacts being the main table/form, Bids the sub, one Contact to potentially many Bids. In the Bid table exists 3 fields that an estimator may need to filter by (possibly all, or just 1), status, bidder, biddate. I need to filter those records and pull up the related Contact information (opposite of finding the contact and related bids). Criteria in my posted db would be: Status=Needs Bid, Status=Pending, Status=Accepted. Bid Date=6/21/15, Bid Date=6/23/15 Bid Date=6/26/15. Bidder=John Doe, Bidder=Ron Paul, Bidder=Sam Anderson.

    This being said, I have dotted my I's and crossed my T's and the code behind my filter button is:
    Code:
    Private Sub filter_Click()
    On Error GoTo errHandler
    'Purpose:   This module illustrates how to create a search form, _
                where the user can enter as many or few criteria as they wish, _
                and results are shown one per line.
    'Note:      Only records matching ALL of the criteria are returned.
    'Author:    Allen Browne (allen@allenbrowne.com), June 2006.
    'Option Compare Database
    'Option Explicit
        'Purpose:   Build up the criteria string form the non-blank search boxes, and apply to the form's Filter.
        'Notes:     1. We tack " AND " on the end of each condition so you can easily add more search boxes; _
                        we remove the trailing " AND " at the end.
        '           2. The date range works like this: _
                            Both dates      = only dates between (both inclusive. _
                            Start date only = all dates from this one onwards; _
                            End date only   = all dates up to (and including this one).
        Dim strWhere As String                  'The criteria string.
        Dim lngLen As Long                      'Length of the criteria string to append to.
        Const conJetDate = "\#mm\/dd\/yyyy\#"   'The format expected for dates in a JET query string.
        '***********************************************************************
        'Look at each search box, and build up the criteria string from the non-blank ones.
        '***********************************************************************
        'Text field example. Use quotes around the value in the string.
        If Not IsNull(Me.statusfilter) Then
            strWhere = strWhere & "([status] = """ & Me.statusfilter & """) AND "
        End If
        If Not IsNull(Me.bidderfilter) Then
            strWhere = strWhere & "([bidder] = """ & Me.bidderfilter & """) AND "
        End If
        If Not IsNull(Me.biddatefilter) Then
            strWhere = strWhere & "([biddate] = " & Format(Me.biddatefilter, conJetDate) & ") AND "
        End If
        
        '***********************************************************************
        'Chop off the trailing " AND ", and use the string as the form's Filter.
        '***********************************************************************
        'See if the string has more than 5 characters (a trailng " AND ") to remove.
        lngLen = Len(strWhere) - 5
        If lngLen <= 0 Then     'Nah: there was nothing in the string.
            MsgBox "No criteria", vbInformation, "Nothing to do."
        Else                    'Yep: there is something there, so remove the " AND " at the end.
            strWhere = Left$(strWhere, lngLen)
            'For debugging, remove the leading quote on the next line. Prints to Immediate Window (Ctrl+G).
            'Debug.Print strWhere
            'Finally, apply the string as the form's Filter.
            Me.bidsheet.Form.filter = strWhere
            Me.bidsheet.Form.FilterOn = True
        
        
        End If
        Debug.Print strWhere
        Exit Sub
    errHandler:
        MsgBox "Error " & Err.Number & ": " & Err.Description & " in " & _
               VBE.ActiveCodePane.CodeModule, vbOKOnly, "Error"
    End Sub
    And when I enter Bidder=Sam Anderson, I get a blank Bid record. If I enter Status=Pending, I get a blank bid record. Same with biddate=10/26/15. I have Query16 that tests for data, and that pulls the proper information. Sigh.

  9. #39
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,771
    It is working properly as designed.

    You get blank because there is no Sam Anderson bidder associated with ContactID 5. As already noted, the subform can only show records associated with the main record form. Same for biddate 10/26/15.

    The query works because it is not linked to a master.

    If you want to be able to search for ANY record then cannot link main and subform. In which case there is no reason to use form/subform arrangement.
    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. #40
    ssanfu is offline Master of Nothing
    Windows XP Access 2010 32bit
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    I'm not sure which control you are referring to that has a space
    Actually, it was a few object names (forms and queries). Didn't notice any controls or variables with spaces.


    And for the record, my code does compile! That's what is driving me nuts, but again, point taken.
    Code will compile, even with errors, if the code modules do not have the line "Option Explicit".

    So went back and checked. I added "Option Explicit" to every code module and tried to compile.
    These are the errors:

    Form: BidSheetwithCustPayments
    Private Sub Needs_BeforeUpdate(Cancel As Integer)
    ctl - Variable not defined
    aryList - Variable not defined
    varSelected - Variable not defined
    strStart - Variable not defined
    strEnd - Variable not defined
    -----------------------------------------------

    Form: Copy Of Bidsheet
    Private Sub Needs_BeforeUpdate(Cancel As Integer)
    ctl - Variable not defined
    aryList - Variable not defined
    varSelected - Variable not defined
    strStart - Variable not defined
    strEnd - Variable not defined
    -----------------------------------------------

    Form: Copy Of Picture Hyperlinks
    Public Function Execute_Program(ByVal strFilePath As String, _
    ByVal strParms As String, ByVal strDir As String) As Boolean
    conVerticalOnly - Variable not defined
    strFilesSelected- Variable not defined


    Private Sub Command0_Click()
    objDialog - Variable not defined
    -----------------------------------------------

    Form: ContractsforBids
    Private Sub Command39_Click()
    MyGoogleMapURL - Variable not defined
    ----------------------------------------------

    Form: BidDetails
    Private Sub Category_NotInList(NewData As String, Response As Integer)
    intAnswer - Variable not defined


    Private Sub Width_AfterUpdate()
    Length - Variable not defined
    -----------------------------------------------

    Form: ContractsforBids
    Private Sub Command39_Click()

    MyGoogleMapURL - Variable not defined
    ----------------------------------------------

    Form: BidDetails
    Private Sub Category_NotInList(NewData As String, Response As Integer)
    intAnswer - Variable not defined


    Private Sub Width_AfterUpdate()
    Length - Variable not defined
    -----------------------------------------------

    Form: Bidsheet
    Private Sub Needs_BeforeUpdate(Cancel As Integer)
    ctl - Variable not defined
    aryList - Variable not defined
    varSelected - Variable not defined
    strStart - Variable not defined
    strEnd - Variable not defined
    -----------------------------------------------

    Report: bidreport
    Private Sub Report_Load()
    MeasurementType - Variable not defined
    yes - Variable not defined '<-- this should actually be TRUE
    no - Variable not defined '<-- this should actually be FALSE
    -----------------------------------------------

    Module: Maps
    Function gglDirectionsResponse(ByVal strStartLocation, ByVal strEndLocation, ByRef strTravelTime, ByRef strDistance, ByRef strInstructions, Optional ByRef strerror = "") As Boolean

    strUnits - Variable not defined
    -----------------------------------------------



    Years ago I heard a saying:
    "If you point at someone, 1 finger is pointing at them, but 3 are pointing back at you".

    So I am not pointing fingers at you.
    I had to remove spaces that crept in yesterday. And as I was copying (reusing) code, I forgot to copy some variables to the code I was modifying ...
    "Option Explicit" caused the compiler to complain and I corrected my oversight. (I need to think faster and type slower)



    I'm just sayin.......

  11. #41
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,771
    And Width and Length are reserved words. Should not use reserved words as names for anything, including 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.

  12. #42
    Gina Maylone is offline Always learning
    Windows 7 64bit Access 2013
    Join Date
    Jun 2013
    Location
    Afton, MN
    Posts
    544
    Yep, changed those awhile ago to Len and Wid - although I supposed Len is a reserved word?

  13. #43
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,771
    Yes, it is an intrinsic function.
    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.

Page 3 of 3 FirstFirst 123
Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 19
    Last Post: 09-25-2015, 10:26 PM
  2. Combobox subform filter: text field vs. number field
    By Alhassani in forum Programming
    Replies: 2
    Last Post: 07-08-2014, 10:04 AM
  3. Replies: 5
    Last Post: 03-15-2013, 10:53 PM
  4. Replies: 19
    Last Post: 07-23-2012, 10:34 AM
  5. Replies: 1
    Last Post: 05-09-2012, 02:22 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