Page 1 of 2 12 LastLast
Results 1 to 15 of 22
  1. #1
    MdHaziq is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Sep 2017
    Location
    Singapore
    Posts
    124

    more than 2 combo boxes


    Hello,

    I have 9 combo boxes which I like to let the user select to get what they want from my dept inventory database.

    I am currently following a youtube tutorial I found in this website thread. It works for the two combo boxes but no more than 2.

    Can anyone help me?

    I have attached the MS Access zip file as the file is bigger than 500KB.

    Thanks

    Yours Sincerely,
    Haziq
    Attached Files Attached Files

  2. #2
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,524
    this is the wrong method.
    if the user is picking departments, instead of 9 boxes,
    use a tPicked table. Put all depts in this table. Join the tPicked table to tData table. Only these will be retrieved.
    This way you are not limited to 9.

    use a list box for the user to dbl-click, this runs an append query to add it to the table.

    Click image for larger version. 

Name:	pick list names.png 
Views:	49 
Size:	28.7 KB 
ID:	30391

  3. #3
    ssanfu is offline Master of Nothing
    Windows 7 32bit Access 2010 32bit
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    You are missing a lot of tables and only 2 combo boxes are configured.


    Attached is an early attempt of mine using multiple 6 cascading combo boxes.
    Be aware I named the tables wrong - the names begin with a number.
    I now know this is a BAD IDEA. (Note to self: I should take the time to fix the naming problems )

    Look at the relationship window to see how the tables are related. Then click on the button "Cascading combo boxes". Try selecting the combo boxes.......

    The other button is cascading list boxes. It is the same as the cascading combo boxes, but using list boxes. Sometimes it is easier to see what is going on using the list boxes...
    Attached Files Attached Files

  4. #4
    MdHaziq is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Sep 2017
    Location
    Singapore
    Posts
    124
    Is using combo boxes to narrow down search a bad idea?

    Should it done via tPicked table?
    BTW this is the first time I heard about tPicked table and got to study it.

    Thanks

  5. #5
    ssanfu is offline Master of Nothing
    Windows 7 32bit Access 2010 32bit
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    Is using combo boxes to narrow down search a bad idea?
    No, not if they meet your requirements.


    tPicked table?
    "tPicked" is just the name ranman named the table he used....can be any name.

  6. #6
    MdHaziq is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Sep 2017
    Location
    Singapore
    Posts
    124
    Oh okay
    Thanks

  7. #7
    MdHaziq is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Sep 2017
    Location
    Singapore
    Posts
    124
    What you send me is beautiful.

    Thanks.

  8. #8
    MdHaziq is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Sep 2017
    Location
    Singapore
    Posts
    124

    Setting up of relationship

    I am having trouble with the relationships.

    The results do not come out in my form.

    I did not input real data as I am just testing it out.

    What went wrong?

    I have inserted an attachment.
    Attached Files Attached Files

  9. #9
    ssanfu is offline Master of Nothing
    Windows 7 32bit Access 2010 32bit
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    Well.... lots..

    OK - here goes:


    I guess you missed this:
    Quote Originally Posted by ssanfu View Post
    <snip>
    Be aware I named the tables wrong - the names begin with a number.
    I now know this is a BAD IDEA. (Note to self: I should take the time to fix the naming problems )
    <snip>
    It is ok when designing (on paper), but don't leave the table names with a number as the first character.
    Click image for larger version. 

Name:	RelationshipBad.png 
Views:	35 
Size:	52.5 KB 
ID:	30462
    Having "ID" as the PK field name is bad programming practice. Imagine looking at queries with multiple tables and there are 4 "ID" fields...... what tables to the "ID" fields belong to???

    Here are the table names and field names renamed:
    Click image for larger version. 

Name:	RelationshipFix.png 
Views:	35 
Size:	77.9 KB 
ID:	30463

    Finally, table "Main" is linked to the other tables and RI is set:
    Click image for larger version. 

Name:	Relationships.png 
Views:	35 
Size:	90.3 KB 
ID:	30464


    The table "QTY" is not needed because you type in the number.

    ================================================== ======================
    Now the form.
    You have to set each combo box row source property and set the combo box formatting.

    The first combo box (cboTerminal) row source is easy:
    Code:
    SELECT tblTerminal.TerminalID_PK, tblTerminal.TerminalDesc
    FROM tblTerminal
    ORDER BY tblTerminal.TerminalDesc;
    (I added a sort order)

    Set the properties:
    Data tab
    Bound column =1
    Limit to List = Yes
    Format tab
    Column count = 2
    Column widths = 0";1" (or however wide you want to combo box)


    The next combo box (cboStore) has to be filtered based on the previous combo box:
    Code:
    SELECT tblStore.StoreID_PK, tblStore.StoreDesc
    FROM tblStore
    WHERE (((tblStore.TerminalID_FK)=[forms]![frmECD_Inventory].[cboTerminal]))
    ORDER BY tblStore.StoreDesc;
    Set the properties:
    Data tab
    Bound column =1
    Limit to List = Yes
    Format tab
    Column count = 2
    Column widths = 0";1" (or however wide you want to combo box)

    The next combo box (cboRack) is filtered based on the previous combo box "cboStore":
    Code:
    SELECT tblRack.RackID_PK, tblRack.RackDesc
    FROM tblRack
    WHERE (((tblRack.StoreID_FK)=[forms]![frmECD_Inventory].[cboStore]))
    ORDER BY tblRack.RackDesc;
    Set the properties:
    - Like above -


    And the next combo box (cboRack) is filtered based on the previous combo box "cboRack":
    -- By now you should be able to figure out the SQL for the row source and the formatting.


    The next thing is to add the after event VBA and the got fucus code.
    Look at the VBA code in my example dB. Start with the last combo box - it only has the got focus code. Each combo box has this code to cause the dropdown to display.
    Then look at the previous com box - it also has the after update event.
    Follow the code for each previous combo box. See what is happening??


    At this point the combo boxes on the form are still unbound.
    After you have all of the combo boxes row sources set, the formatting set and the VBA added, you can bind the combo boxes to the appropriate fields in the form. The form record source should be a query based on the "Main" table (or directly to the table).

  10. #10
    MdHaziq is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Sep 2017
    Location
    Singapore
    Posts
    124
    Thank you so much for explaining to me.

    I appreciate it.

    I will get coding as soon as I get back home.

  11. #11
    MdHaziq is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Sep 2017
    Location
    Singapore
    Posts
    124

    Cascading cboboxes

    Steve,

    I have done the part which you walked me through.

    If possible could you walk me though the next portion?

    Thanks

    This is what I got so far
    Attached Files Attached Files

  12. #12
    ssanfu is offline Master of Nothing
    Windows 7 32bit Access 2010 32bit
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    On the form, the text box "txtqty" should NOT have a control source of "=[tblmain]![Qty]" and should NOT have any code in the after update event.


    The next thing is to add the after event VBA and the got focus code.
    Look at the VBA code in my example dB. Start with the last combo box - it only has the got focus code. Each combo box has this code to cause the dropdown to display.
    Then look at the previous com box - it also has the after update event.
    Follow the code for each previous combo box. See what is happening??
    First, these two lines should be the top two lines of EVERY nodule:
    Code:
    Option Compare Database
    Option Explicit
    -------------------------
    "cboitem"

    Starting at the bottom combo box "cboitem", add the code for the Got Focus event.
    Code:
    Private Sub cboitem_GotFocus()
        Me.cboitem.Dropdown
    End Sub
    Since you are changing the selection in "cboItem", you should/could also set the quantity to NULL in the After Update event:
    Code:
    Private Sub cboitem_AfterUpdate()
        Me.txtqty = Null
    End Sub
    -------------------------
    "cboEquipment"
    Moving up one combo box "cboEquipment". It should have the (or it is nice to have) code for the Got Focus event:
    Code:
    Private Sub cboequipment_GotFocus()
        Me.cboequipment.Dropdown
        Me.txtqty = Null
    End Sub
    Changing the Equipment selection, you should clear the "cboItem" combo box and delete the quantity. So there should be code in the after update event to set "cboitem" to NULL, set "txtQty to NULL, then requery "cboitem".
    Code:
    Private Sub cboequipment_AfterUpdate()
        Me.cboitem = Null
        Me.txtqty = Null
        Me.cboitem.Requery
    End Sub
    -------------------------
    Do these steps for the rest of the combo boxes.
    If you have trouble, look at the code in "Impact9A.accdb" above.


    =============================================
    When the combo boxes are functioning correctly, set the form record source to "tblMain" (I would use a query, but that is your choice),
    Then bind the combo boxes to the correct fields.

    Fill the tables (NOT tblMain) with real data.
    Set the "Data Entry" property in form "frmECD_Inventory" to YES.

    Start testing........

  13. #13
    MdHaziq is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Sep 2017
    Location
    Singapore
    Posts
    124

    How to set record source?

    Hello, Steve,
    I gave it a shot but something must be wrong.
    I have done the necessary above but I do not know how to set the record source.

    I have not gone through your program. I will when I get home.

    TIA

    Haziq
    Attached Files Attached Files

  14. #14
    ssanfu is offline Master of Nothing
    Windows 7 32bit Access 2010 32bit
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    Doesn't look like you looked at the code in the Impact example dB.

    Each of the combo boxes GotFocus events should have only 1 line - the name of the combo box and the Dropdown command.
    Examples:
    Code:
    Private Sub cboitem_GotFocus()
        Me.cboitem.Dropdown
    End Sub
    
    Private Sub cboequipment_GotFocus()
        Me.cboequipment.Dropdown
    End Sub
    
    Private Sub cbosystem_GotFocus()
        Me.cbosystem.Dropdown
    End Sub

    Starting at the bottom combo box for the cascaded combo boxes:

    The Item combo box code looks good:
    Code:
    Private Sub cboitem_AfterUpdate()
        Me.txtqty = Null  "good
        Me.txtqty.SetFocus  '<<-- ADD this line - moves to the next control - txtqty
     End Sub
    The next combo box is Equipment combo box - the code has problems:
    Code:
    Private Sub cboequipment_AfterUpdate()
        Me.txtqty = Null  '<<-- MOVED from the cboequipment_GotFocus event
        Me.cboitem = Null   'good
        Me.cboequipment = Null  '<< WHAT??? Really??? You just cleared the value you just selected in the Equipment combo box!!! DELETE this line
        Me.cboitem.Requery
    
        Me.cboitem.SetFocus  '<<-- ADD this line - moves to the next control - cboitem
    End Sub
    Next combo box is System - - the code has problems:
    Code:
    Private Sub cbosystem_AfterUpdate()
        Me.txtqty = Null  '<<-- MOVED from the cbosystem_GotFocus event
        Me.cboitem = Null        'good
        Me.cboequipment = Null   'good
    '    Me.cbosystem = Null     '<< WHAT??? Really??? You just cleared the value you just selected in the System combo box!!! DELETE this line
        Me.cboitem.Requery
                  'What about the requery for cboequipment???
        Me.cboequipment.Requery   '<<-- ADD this line
    
        Me.cboequipment.SetFocus  '<<-- ADD this line- moves to the next control - cboequipment
    End Sub

    See how this works?? Continue with the other combo boxes
    cboRack
    cboStore
    cboTerminal

  15. #15
    MdHaziq is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Sep 2017
    Location
    Singapore
    Posts
    124
    Thx for debuging for me.
    I will read your code first thing when I get to the office.

Page 1 of 2 12 LastLast
Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 5
    Last Post: 09-22-2016, 08:42 AM
  2. Changing text boxes to combo boxes
    By Lou_Reed in forum Access
    Replies: 8
    Last Post: 09-15-2015, 11:09 AM
  3. Linking Combo boxes and Text boxes
    By Nathan4477 in forum Forms
    Replies: 6
    Last Post: 07-29-2015, 08:50 AM
  4. Replies: 11
    Last Post: 08-06-2014, 09:47 AM
  5. Replies: 9
    Last Post: 06-04-2014, 10:45 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