Results 1 to 8 of 8
  1. #1
    ErikAE is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Aug 2014
    Posts
    7

    Auto Complete Cascading Combo Box If Only Single Record Left

    Hi.



    I have several cascading combo boxes that filters data; one combo box filtering data for the following combo box.

    In some situations however, there may only be a single record to choose from in a combo box.

    Is there a way to automatically fill the combo box & any other following combo boxes when there is only one option to choose from?

    Regards.
    Erik.

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,930
    Bing: vba select first item combobox
    http://support.microsoft.com/kb/105519

    If you want conditional:

    If Me.combobox.ListCount = 1 Then
    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.

  3. #3
    ErikAE is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Aug 2014
    Posts
    7
    Thanks.

    It put me on the right track to solve the issue. Just in case this may be useful for anyone looking for a solution to auto-populating cascading combo boxes:

    Private Sub FIRST_COMBOBOX_Change() <--- Place code in first or preceding combo box's 'On Change' property


    Me.SECOND_COMBOBOX.Requery <--- Refresh 2nd cascading combo box


    If Me.SECOND_COMBOBOX.ListCount = 1 Then <--- Checks to see if there is only a single record in the 2nd combo box


    With Me.SECOND_COMBOBOX
    SECOND_COMBOBOX.SetFocus
    SECOND_COMBOBOX.Value = SECOND_COMBOBOX.ItemData(0)
    End With
    End If


    End Sub



  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
    I would use the first combobox AfterUpdate event.

    If you are going to explicitly reference SECOND_COMBOBOX then the With End With lines accomplish nothing. Consider:

    With Me.SECOND_COMBOBOX
    .Requery
    If .ListCount = 1 Then
    .SetFocus
    .Value = .ItemData(0)
    End If
    End With
    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
    ErikAE is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Aug 2014
    Posts
    7
    Ok.

    I used your snippet of code but it does not auto populate the second combo box; I still have to go in & select the record. Was that the intended effect?

    The code I specified earlier works fine as it does what it intends to do but I welcome anything that makes it more efficient. Thanks.

  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
    No, was not the intended effect. The code should work. I am just saying if you explicitly reference the second combobox on each line, the With End With lines don't serve any purpose - they don't hurt just don't really do anything.
    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
    ErikAE is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Aug 2014
    Posts
    7
    Oh right; thanks for that. I'll play around with it & see how it turns out. Appreciate the help.

    On a different note, I do have another couple of queries; should I create a new thread for these?

  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
    Yes. New topic, new thread.
    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.

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

Similar Threads

  1. Auto Complete A Subform
    By dgutsche in forum Forms
    Replies: 1
    Last Post: 08-14-2014, 04:10 PM
  2. Replies: 6
    Last Post: 02-01-2013, 10:02 AM
  3. Replies: 3
    Last Post: 12-19-2012, 08:35 AM
  4. Replies: 3
    Last Post: 11-04-2011, 01:50 PM
  5. Replies: 63
    Last Post: 09-16-2011, 04:55 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