Results 1 to 5 of 5
  1. #1
    JCW is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Apr 2014
    Posts
    8

    Question Cascading Combo Boxes

    Looking for help on cascading combo boxes

    I have two tables: tclient and tmatter. The tables share a common key based on the clientId.

    I have a form with two combo boxes cmbMatterNo for the matter name and cmbClientSearch for the client name. When I select an item from the cmbMatterNo it runs a query on the tmatter table that returns the clientID and the matterNo, with the clientID being the bound column. I want to synch the cmbClientName based on the selection of the matterNo in the cmbMatterNo combobox,

    I have written the following code:

    cmbClientName.RowSource = "SELECT tClients.ClientID, tClients.ClientName " & _


    "FROM tClients " & _
    "WHERE tClients.ClientID = '" & cmbMatterNo.Value & "' " & _
    "ORDER BY tClients.ClientName;"

    When I select the cmbMatterNo item it returns the clientID as the cmbMatterNo.Value, but the cmbClientName box nevertheless is empty and does not show any of client name from the tclients table.

    Any help on what I am doing wrong would be greatly appreciated.

    Thanks.

  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,931
    Set cmbClientName properties:

    ColumnCount: 2

    ColumnWidths: 0";1.5"


    Is cmbMatterNo an UNBOUND (no ControlSource) combobox?
    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
    JCW is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Apr 2014
    Posts
    8
    cmbClientName is already set to 2 columns, with widths of 0";4", and cmbMatterNo is unbound.

    (Also my reference in the thread to cmbClientSearch was a mistake. It should be cmbClientName).

  4. #4
    JCW is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Apr 2014
    Posts
    8
    Solved the problem. Deleted the ' ... ' from '" & Me!cboClientName.Value & "' and the problem resolved. Not sure I understand why, but am happy nevertheless.

  5. #5
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,931
    You deleted the apostrophes? Ooops! I should have noticed that.

    When constructing SQL in VBA, apostrophes are need to delimit text values for text data type fields. ClientID is apparently a number field so no apostrophes needed. Criteria for date/time type fields would use # delimiter.

    However, it is not necessary to set the RowSource with VBA. Can just have the SQL in the RowSource property:

    SELECT ClientID, ClientName FROM tClients WHERE ClientID = [cmbMatterNo] ORDER BY ClientName;

    Then the VBA just needs to be:

    Me.cmbClientName.Requery
    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. cascading Combo boxes
    By Chatholo in forum Forms
    Replies: 2
    Last Post: 08-09-2013, 01:39 AM
  2. Cascading combo boxes
    By Jackie in forum Access
    Replies: 5
    Last Post: 07-26-2013, 09:07 AM
  3. Cascading Combo boxes
    By finsmith in forum Forms
    Replies: 10
    Last Post: 02-12-2013, 09:37 AM
  4. Sum of Cascading Combo Boxes
    By alonewolf23 in forum Forms
    Replies: 2
    Last Post: 11-20-2011, 02:10 PM
  5. Cascading Combo Boxes
    By gjw1012 in forum Access
    Replies: 1
    Last Post: 07-25-2009, 04:59 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