Results 1 to 10 of 10
  1. #1
    tbbrown32 is offline Advanced Beginner
    Windows 7 32bit Access 2010 32bit
    Join Date
    Dec 2015
    Posts
    79

    Combo Box will not update when record changes

    Hi everyone,

    In my current database, I have a table named tblIncidents asthe table behind my main form. My main data entry form is based on the Incident#(the PK for tblIncidents). In most cases, all tables are related to this onevia associative tables to resolve the many to many relationship issue. However,I have one table that is one relationship further away from tblIncidents.Please see the attachment for the table layout.

    I have a cboClassType that allows me to selectClassificationType which filters my next cboClassName and allows me to choose aClassificationName that falls under the selected type. As I scroll through myrecords, I can get cboClassName to update but not cboClassType because myrecords are based off of InternalIncidentID which is not present intblClassificationTypes.


    I am at a loss how to get both cbos to update as I scrollthrough records based on tblIncidents. My current code that works for cboClassName is below. Is there a way I can adapt that or do a JOIN so that I can get cboClassType to update as the record changes? Any help would be much appreciated!!!

    Code:
    Private Sub UpdatecboClassName() ' Runs when the Classification combo box is updated and shows the existing record in the IncidentClassifications table for that particular InternalIncidentID '
        Dim db As DAO.Database
        Dim rs As DAO.Recordset
        Dim strSQL As String
        Me.cboClassName.Value = Empty
        strSQL = "SELECT [tblIncidentClassifications].[ClassificationID]"
        strSQL = strSQL & " FROM tblIncidentClassifications"
        strSQL = strSQL & " WHERE tblIncidentClassifications.InternalIncidentID = '" & Me.InternalIncidentID & "';"
        '        Debug.Print strSQL
        Set rs = CurrentDb.OpenRecordset(strSQL)
        If Not rs.BOF And Not rs.EOF Then
            Me.cboClassName = rs("ClassificationID")
        End If
        rs.Close
        Set rs = Nothing
        Set db = Nothing
    End Sub
    Attached Thumbnails Attached Thumbnails Image.PNG  

  2. #2
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,550
    The combo box MUST be updated after the record changes.
    either click the UPDATE ALL button on the toolbar,
    or
    refresh in code:
    cboBox.requery

  3. #3
    tbbrown32 is offline Advanced Beginner
    Windows 7 32bit Access 2010 32bit
    Join Date
    Dec 2015
    Posts
    79
    When I go to a different record and click update all it doesn't refresh cboClassType, I think because there is no code telling Access that an InternalIncidentID and the corresponding ClassificationID are related through multiple tables to a specific ClassificationTypeID.

  4. #4
    davegri's Avatar
    davegri is offline Excess Access
    Windows 10 Access 2016
    Join Date
    May 2012
    Location
    Denver
    Posts
    3,740
    What's the rowsource for cboClassType?
    Last edited by davegri; 12-16-2016 at 12:40 PM. Reason: change

  5. #5
    tbbrown32 is offline Advanced Beginner
    Windows 7 32bit Access 2010 32bit
    Join Date
    Dec 2015
    Posts
    79
    The rowsource is
    Code:
    SELECT tblClassificationTypes.ClassificationTypeID, tblClassificationTypes.ClassificationTypeName FROM tblClassificationTypes;

  6. #6
    davegri's Avatar
    davegri is offline Excess Access
    Windows 10 Access 2016
    Join Date
    May 2012
    Location
    Denver
    Posts
    3,740
    Code:
    Private Sub UpdatecboClassName() ' Runs when the Classification combo box is updated and shows the existing record in the IncidentClassifications table for that particular InternalIncidentID '
        Dim db As DAO.Database
        Dim rs As DAO.Recordset
        Dim strSQL As String
        Me.cboClassName.Value = Empty
        strSQL = "SELECT [tblIncidentClassifications].[ClassificationID]"
        strSQL = strSQL & " FROM tblIncidentClassifications"
        strSQL = strSQL & " WHERE tblIncidentClassifications.InternalIncidentID = '" & Me.InternalIncidentID & "';"
        '        Debug.Print strSQL
        Set rs = CurrentDb.OpenRecordset(strSQL)
        If Not rs.BOF And Not rs.EOF Then
            Me.cboClassName = rs("ClassificationID")
        End If
        rs.Close
        Set rs = Nothing
        Set db = Nothing
    First, try deleting all the red. Single quotes indicate a string, not a long or autonumber.
    Last edited by davegri; 12-16-2016 at 03:28 PM. Reason: clarity

  7. #7
    davegri's Avatar
    davegri is offline Excess Access
    Windows 10 Access 2016
    Join Date
    May 2012
    Location
    Denver
    Posts
    3,740
    When scrolling thru records, the cboUpdate events do not fire.
    In the form_current event, try calling sub UpdatecboClassName.

  8. #8
    tbbrown32 is offline Advanced Beginner
    Windows 7 32bit Access 2010 32bit
    Join Date
    Dec 2015
    Posts
    79
    I still am having the same issue. The code I posted works for cboClassName but not cboClassType because of the lack of a shared field based on InternalIncidentID. As all my forms are based primarily off of the InternalIncidentID, the ClassificationType table needs to be able to update, but I'm not sure how to go about structuring that code.

  9. #9
    John_G is offline VIP
    Windows 7 32bit Access 2010 32bit
    Join Date
    Oct 2011
    Location
    Ottawa, ON (area)
    Posts
    2,615
    If you are not using a main form - sub form arrangement, then I think you need to do so. Your relationship diagram shows a one-to-many relationship between incident and IncidentClassification, which needs a main form - subform. Your combos would apply only to records in the subform.

  10. #10
    tbbrown32 is offline Advanced Beginner
    Windows 7 32bit Access 2010 32bit
    Join Date
    Dec 2015
    Posts
    79
    Thanks to everyone for the responses. I appreciate the assistance!

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

Similar Threads

  1. Replies: 12
    Last Post: 02-15-2016, 11:10 AM
  2. Replies: 19
    Last Post: 04-27-2015, 06:57 AM
  3. Replies: 7
    Last Post: 03-30-2015, 10:04 AM
  4. Replies: 1
    Last Post: 07-25-2013, 09:41 AM
  5. Replies: 1
    Last Post: 08-09-2012, 04:19 PM

Tags for this Thread

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