Results 1 to 7 of 7
  1. #1
    Join Date
    May 2011
    Posts
    6

    Unanswered: cascading comboboxes

    Hello,

    I have a form that will show all the clients that I have. As I have many records I need to filter those records by alphabetical order. So, I thought that cascading comboboxes would be the solution. The first one would have the alphabet and the second one would have the records according with the letter chose.

    So, if the cbofirst.letter is the first combobox, and the cbonome is the second, the following is my code so far:


    Private Sub cbofirstletter_AfterUpdate()
    Dim db As DAO.Database
    Dim rst As DAO.Recordset
    Dim fletter As String
    Set db = CurrentDb
    Set rst = db.OpenRecordset("tblclientes", dbOpenDynaset)
    Me!Cbonome = Null
    If IsNull(cbofirstletter) Then
    Me!cbofirst.letter.SetFocus
    Me!Cbonome.Enabled = False
    Else
    Me!Cbonome.Enabled = True
    With rst
    fletter = Me!cbofirstletter.Value
    Me!Cbonome.RowSource = "SELECT fldnome " _
    & "FROM tblclientes " _
    & "WHERE fldnome Like " & fletter *
    Me!Cbonome.Requery
    End With
    End If
    End Sub


    I can't make this work, and I think the problem is in the query statement. I have looked in several books and sites and I can't find the solution.

    So, if you help me I would be glad. thank you in advance.

    Regards

  2. #2
    Join Date
    Apr 2005
    Location
    Zagreb - Croatia
    Posts
    372
    Look at "DemoAlphabeticalComboA2000.mdb" (attachment, zip).
    I put in "tblAlphabetical" A-E letters, (you put the rest).
    Look at tables, Form1 (VBA), open form and try.
    Attached Files Attached Files

  3. #3
    Join Date
    May 2011
    Posts
    6
    Hello again,

    thank you MStef-ZG! I have looked into your file and it makes almost what I need. However, I wanted also to put an ALL on the first combo box, which would show all records in the second combobox. It only can be done on VBA right?

    Once again, thank you.

    Regards

  4. #4
    Join Date
    Apr 2005
    Location
    Zagreb - Croatia
    Posts
    372
    OK. Look at "Demo" a new one.
    I added smo VBA.
    For All records in Combo2, leave Combo1 empty,
    and click on the ENTER button.
    Attached Files Attached Files

  5. #5
    Join Date
    Mar 2009
    Posts
    5,442
    Provided Answers: 14
    You can also add a zero-lenght string row to the table tblAlphabets.
    Have a nice day!

  6. #6
    Join Date
    May 2011
    Posts
    6
    It works just fine!

    Thank you Sinndho and MStef-ZG.

    Regards

  7. #7
    Join Date
    Mar 2009
    Posts
    5,442
    Provided Answers: 14
    You're welcome!
    Have a nice day!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •