Results 1 to 4 of 4
  1. #1
    Gold Lounger
    Join Date
    Jan 2004
    Location
    Italy
    Posts
    3,245
    Thanks
    0
    Thanked 0 Times in 0 Posts

    fill combo with unique value... (2000)

    Ho to fill the combo with unique value based WHERE and PROVA1...
    Use this code butr not sure...

    note:
    If i use distinct PROVA1 the code go in error whene call PROVA2...

    Sub FILL_COMBO_MERCATO_AREA(REGIONE)

    Set RSSQL4 = New ADODB.Recordset

    SSQL = Empty
    SSQL = "SELECT PROVA1,PROVA2 FROM MERCATI WHERE PROVA7= '" & REGIONE & "' ORDER BY PROVA1 ASC"
    RSSQL4.Open SSQL, CNSQL, adOpenForwardOnly, adLockReadOnly

    RSSQL4.MoveFirst
    With Me.MERCATO_AREA
    .Clear
    Do While Not RSSQL4.EOF
    'TEST = RSSQL4!MERCATO
    'Debug.Print TEST
    .AddItem Trim(RSSQL4!PROVA1) & "- " & Trim(RSSQL4!PROVA2)
    TEST_RST = RSSQL4!PROVA1
    'Debug.Print TEST_RST
    RSSQL4.MoveNext
    Loop

    End With

    RSSQL4.Close
    Set RSSQL4 = Nothing

    End Sub

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

    Re: fill combo with unique value... (2000)

    SELECT DISTINCT acts on all fields that you return, i.e. it will select unique combinations of PROVA1 and PROVA2.
    If you want to return unique values of PROVA1 only, you must specify which value of PROVA2 you want for each PROVA1: the first, or the highest, or ...

  3. #3
    Gold Lounger
    Join Date
    Jan 2004
    Location
    Italy
    Posts
    3,245
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: fill combo with unique value... (2000)

    Tks for explain....
    But arranged a old code, wath you think about:
    Sub FILL_COMBO_MERCATO_AREA(REGIONE)

    Set RSSQL4 = New ADODB.Recordset

    SSQL = Empty
    SSQL = "SELECT PROVA1,PROVA2 FROM MERCATI WHERE PROVA7= '" & REGIONE & "' ORDER BY PROVA1"
    RSSQL4.Open SSQL, CNSQL, adOpenForwardOnly, adLockReadOnly

    TEST_RST = Empty

    RSSQL4.MoveFirst
    With Me.MERCATO_AREA
    .Clear
    Do While Not RSSQL4.EOF
    If TEST_RST <> RSSQL4!PROVA1 Then
    .AddItem Trim(RSSQL4!PROVA1) & "- " & Trim(RSSQL4!PROVA2)
    End If
    TEST_RST = RSSQL4!PROVA1
    RSSQL4.MoveNext
    Loop

    End With

    RSSQL4.Close
    Set RSSQL4 = Nothing

    End Sub

  4. #4
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: fill combo with unique value... (2000)

    That should work. Keep in mind that this code will use the FIRST value of PROVA2 it encounters for each value of PROVA1.

Posting Permissions

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