Results 1 to 3 of 3
  1. #1
    Laurens is offline Novice
    Windows 10 Access 2016
    Join Date
    Jul 2018
    Posts
    1

    Combobox filter based on other combo box

    I am creating 2 combo boxes, where the possible selections of the second combobox need to depend on the selected part in the first combo box.

    I use:
    * Windows 10
    * Access 2016

    The code that I have used is:



    Code:
    Private Sub Combo269_AfterUpdate()    Dim sTypeSource As String
        
        sTypeSource = "SELECT [Type List].[ID], [Type List].[Brand], [Type List].[Type] " & _
                            "FROM [Type List] " & _
                            "WHERE [Brand] ='" & Me.Combo269.Value 
        Me.Combo290.RowSource = sTypeSource
        Me.Combo290.Requery
    End Sub
    Where combo269 is the first combobox and Combo290 is the second.

    The second combobox now doesn't give results. I already found what is causing this, but I can't find the solution.

    With this code the result given in the combobox290

    SELECT [Type List].[ID], [Type List].[Brand], [Type List].[Type] FROM [Type List] WHERE [Brand] ='Alfa Romeo

    This needs to be:
    SELECT [Type List].[ID], [Type List].[Brand], [Type List].[Type] FROM [Type List] WHERE [Brand] ='Alfa Romeo'

    So only the ' at the end needs to be added to show good results. I tried to do this in the code with "'" behind "WHERE [Brand] ='" & Me.Combo269.Value

    But this gives a syntax error. Anyone knowing what the correct part needs to be to solve this minor issue? I think it is something very very very simple but I can't nail it down.

    Thanks in advanced for the help

  2. #2
    CJ_London is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,933
    what is the syntax error? and show the code you are actually using.

    also you do not need to refer to .value since it is the default and there is no need to requery since your are changing the rowsource.

    Your code could be much simpler - just code your combo290 rowsource with

    SELECT [Type List].[ID], [Type List].[Brand], [Type List].[Type] FROM [Type List] WHERE [Brand] =[combo269]

    and the code in the combo269 afterupdate event would then just be

    Me.Combo290.Requery

    Finally, strongly recommend you use meaningful names for your controls, particularly if you want help since it makes understanding your code much easier

  3. #3
    Gicu's Avatar
    Gicu is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jul 2015
    Location
    Kelowna, BC, Canada
    Posts
    4,250
    Try:
    Code:
     sTypeSource = "SELECT [Type List].[ID], [Type List].[Brand], [Type List].[Type] " & _
                            "FROM [Type List] " & _
                            "WHERE [Brand] ='" & Me.Combo269.Value & "'"
    Cheers,
    Vlad

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

Similar Threads

  1. Replies: 3
    Last Post: 03-02-2016, 06:05 PM
  2. Replies: 1
    Last Post: 09-06-2011, 01:47 PM
  3. Replies: 29
    Last Post: 08-16-2011, 05:52 PM
  4. Replies: 0
    Last Post: 08-24-2010, 06:38 PM
  5. Replies: 0
    Last Post: 12-16-2009, 01:14 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