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. #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)

  3. #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
  •