Results 1 to 3 of 3
  1. #1
    5 Star Lounger
    Join Date
    Jan 2005
    Posts
    614
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Combo box values (Access2003)

    Hello again!

    I have 4 comboboxes where i am selecting values and I want to have values in following combobox displayed based on value selected in previous combobox.

    I am trying

    Private Sub cmbTop_XXX(Cancel As Integer)
    Dim mySQL As String
    Dim OfficeCode As String

    OfficeCode = cmbOffice.Value

    mySQL = "SELECT DISTINCT EXTENSION FROM Table_Main where [Office code]=OfficeCode"

    End Sub

    However it wouldn't work. I am assuming I can't find correct event or maybe something else is wrong? Please, advise. Thanks

  2. Subscribe to our Windows Secrets Newsletter - It's Free!

    Get our unique weekly Newsletter with tips and techniques, how to's and critical updates on Windows 7, Windows 8, Windows XP, Firefox, Internet Explorer, Google, etc. Join our 480,000 subscribers!

    Excel 2013: The Missing Manual

    + Get this BONUS — free!

    Get the most of Excel! Learn about new features, basics of creating a new spreadsheet and using the infamous Ribbon in the first chapter of Excel 2013: The Missing Manual - Subscribe and download Chapter 1 for free!

  3. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 16 Times in 16 Posts

    Re: Combo box values (Access2003)

    Since OfficeCode is within the quotes, it is interpreted as a field name. You cannot use VBA variables directly in an SQL string, you must use concatenation instead.

    If Office Code is a number field:

    mySQL = "SELECT DISTINCT EXTENSION FROM Table_Main where [Office code]=" & OfficeCode

    If it is a text field:

    mySQL = "SELECT DISTINCT EXTENSION FROM Table_Main where [Office code]=" & Chr(34) & OfficeCode & Chr(34)

  4. #3
    5 Star Lounger
    Join Date
    Jan 2005
    Posts
    614
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Combo box values (Access2003)

    THANKS as always!

Posting Permissions

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