Results 1 to 6 of 6
  1. #1
    ittechguy is offline Competent Performer
    Windows 8 Access 2013
    Join Date
    Aug 2015
    Posts
    218

    AfterUpdate requery does not requery list box

    I'm building a rather complex search form (for my understanding of access). The project is coming along nicely. One of the problems I'm having is that my list boxes are not re-querying after the values in txtBuildingID and txtRoomsID changes. You can see in the photo below, there are 19 records. I can scroll through the records or I can search for records to narrow down results. Every time I go to a different record there are different results in both text boxes. I need the list boxes below (lstFacilityMgr, lstRoomsPOC, and lstEquipmentInRoom) to requery. For some reason, this is not happening. I tried using Change instead of AfterUpdate, same results.

    Click image for larger version. 

Name:	layout.png 
Views:	14 
Size:	33.7 KB 
ID:	22346

    My code is below:



    Code:
    Option Compare DatabaseOption Explicit  'always set this  It will point out errors with field/vaiable names
    
    
    
    
    Private Sub cboSearchLastName_AfterUpdate()
        Me.cboSearchFirstName.Requery
    End Sub
    
    
    Private Sub cboSearchOrganization_AfterUpdate()
        Me.cboSearchShopName.Requery
    End Sub
    
    
    Private Sub cboSearchShopName_AfterUpdate()
        Me.cboSearchOfficeSym.Requery
    End Sub
    
    
    Private Sub cmdReset_Click()
        Me.cboSearchBuildingName = ""
        Me.cboSearchRoomName = ""
        Me.cboSearchOrganization = ""
        Me.cboSearchShopName = ""
        Me.cboSearchOfficeSym = ""
        Me.cboSearchLastName = ""
        Me.cboSearchFirstName = ""
        Me.FilterOn = False
    End Sub
    Private Sub txtBuildingID_AfterUpdate()
        Me.lstFacilityMgr.Requery
    End Sub
    
    
    Private Sub txtRoomsID_AfterUpdate()
        Me.lstRoomsPOC.Requery
    End Sub
    Private Sub cmdSearch_Click()
        Dim strWhere As String
        Dim lngLen As Long
        Dim startStr As String
        If Not IsNullOrEmpty(Me.cboSearchLastName) Then
            startStr = IIf(strWhere = "", "", " AND ")
            
            strWhere = strWhere & startStr & "[LastName] ='" & Me.cboSearchLastName & "'"
        End If
        If Not IsNullOrEmpty(Me.cboSearchFirstName) Then
            startStr = IIf(strWhere = "", "", " AND ")
            
            strWhere = strWhere & startStr & "[FirstName] ='" & Me.cboSearchFirstName & "'"
        End If
        If Not IsNullOrEmpty(Me.cboSearchOrganization) Then
            startStr = IIf(strWhere = "", "", " AND ")
            
            strWhere = strWhere & startStr & "[OrganizationFK] =" & Me.cboSearchOrganization
        End If
        If Not IsNullOrEmpty(Me.cboSearchShopName) Then
            startStr = IIf(strWhere = "", "", " AND ")
            
            strWhere = strWhere & startStr & "[ShopNameFK] =" & Me.cboSearchShopName
        End If
        If Not IsNullOrEmpty(Me.cboSearchOfficeSym) Then
            startStr = IIf(strWhere = "", "", " AND ")
            strWhere = strWhere & startStr & "[OfficeSymFK] =" & Me.cboSearchOfficeSym
        End If
        If Not IsNullOrEmpty(Me.cboSearchBuildingName) Then
            startStr = IIf(strWhere = "", "", " AND ")
            strWhere = strWhere & startStr & "[BuildingFK] =" & Me.cboSearchBuildingName
        End If
        If Not IsNullOrEmpty(Me.cboSearchRoomName) Then
            startStr = IIf(strWhere = "", "", " AND ")
            strWhere = strWhere & startStr & "[RoomsPK] =" & Me.cboSearchRoomName
        End If
        If Not IsNullOrEmpty(Me.cboSearchEquipmentName) Then
            startStr = IIf(strWhere = "", "", " AND ")
            strWhere = strWhere & startStr & "[EquipmentNameFK] =" & Me.cboSearchEquipmentName
        End If
        If Not IsNullOrEmpty(Me.cboSearchEquipmentSerialNo) Then
            startStr = IIf(strWhere = "", "", " AND ")
            strWhere = strWhere & startStr & "[SerialNoFK] =" & Me.cboSearchEquipmentSerialNo
        End If
        Call MsgBox(strWhere, vbOKOnly, "Debug")
        lngLen = Len(strWhere) - 5
        If lngLen <= 0 Then
            MsgBox "No criteria", vbInformation, "Nothing to do."
        Else
            'strWhere = Left$(strWhere, lngLen)
            MsgBox strWhere
             If DCount("*", "qryRecordSet", strWhere) = 0 Then
                    MsgBox "No corresponding records to your search criteria." & vbCrLf & vbCrLf
                    Me.FilterOn = False
                    Me.cboSearchBuildingName = ""
                    Me.cboSearchRoomName = ""
                    Me.cboSearchOrganization = ""
                    Me.cboSearchShopName = ""
                    Me.cboSearchOfficeSym = ""
                    Me.cboSearchLastName = ""
                    Me.cboSearchFirstName = ""
             Else
                Me.Filter = strWhere
                Me.FilterOn = True
            End If
        End If
    End Sub
    
    
    
    
    
    
    Function IsNullOrEmpty(val As Variant) As Boolean
       'First conditional validates for Nothing
       'Second condition validates for an Empty String situation "" or "     "
       Dim ret As Boolean: ret = False
       If IsMissing(val) Then
          ret = True
       ElseIf (val Is Nothing) Then
          ret = True
       ElseIf (val & vbNullString = vbNullString) Then
          ret = True
       ElseIf (Len(Trim(val)) <= 0) Then
          ret = True
       End If
     
       IsNullOrEmpty = ret
    End Function
    Thank you for your help. I hope its an easy fix.

  2. #2
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    Those events only fire if the user enters something in the textbox. If you want to react to changing records, try the current event.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    ittechguy is offline Competent Performer
    Windows 8 Access 2013
    Join Date
    Aug 2015
    Posts
    218
    Quote Originally Posted by pbaldy View Post
    Those events only fire if the user enters something in the textbox. If you want to react to changing records, try the current event.
    OMG you're a genius! That worked perfectly. Thanks.

  4. #4
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    Happy to help!
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  5. #5
    Erictsang is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Jul 2017
    Posts
    154
    dear Pbaldy

    I am having the similar problem

    i have an input form with a combox or user to choose

    Based on the choice, it triggers the query

    But if we do re-enter again. the query do not change, i have either close it and reopen or click the refresh twice

    How can i solve it /

    Eric

  6. #6
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    If the query is used for a form, you'd have to requery the form. I wouldn't open a query directly, and I doubt there's a way to control it if that's what you're doing.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

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

Similar Threads

  1. requery
    By texas1014 in forum Queries
    Replies: 7
    Last Post: 06-18-2015, 02:55 PM
  2. requery
    By raffi in forum Forms
    Replies: 2
    Last Post: 01-05-2015, 01:22 PM
  3. Requery
    By Grizz2 in forum Queries
    Replies: 2
    Last Post: 05-31-2011, 10:23 AM
  4. Dependent List Boxes do not refresh using ReQuery
    By weeblesue in forum Programming
    Replies: 2
    Last Post: 03-28-2011, 08:47 AM
  5. Requery?
    By CO711 in forum Forms
    Replies: 0
    Last Post: 08-06-2008, 08:03 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