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

    LOOP in rset based var (2000)

    Admit have this table (see image)
    And have a var filled ="BUSINESS"
    How to loop all SETT based this var?
    I think i can use select dinstinc to get all rset with BUSINESS but not idea to loop the value in SETT filed.... <img src=/S/confused.gif border=0 alt=confused width=15 height=20>
    note: conn is the tipical ADO connection, table name is SETTORI...

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

    Re: LOOP in rset based var (2000)

    Open a recordset based on the SQL string
    <code>
    strSQL = "SELECT SETT FROM SETTORI WHERE MERCATO = 'BUSINESS'"
    </code>
    and loop through the records of this recordset.

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

    Re: LOOP in rset based var (2000)

    yes ok....
    i know the dinstinct statement...

    but dubt for looping..
    i can use a for next or do untuil rset eof...

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

    Re: LOOP in rset based var (2000)

    When looping through a recordset rst, you can use

    Do While Not rst.EOF
    ...
    ...
    rst.MoveNext
    Loop

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

    Re: LOOP in rset based var (2000)

    WOW!!!
    The code loop in all MERCATO, why???

    note: MERCATO_SEL is dimensioned string, and assume the value "BUSINESS"

    Public Function LOOP_1(MERCATO_SEL)

    Set RSSQL4 = New ADODB.Recordset

    RSSQL4.Open "SETTORI", CNSQL, adOpenForwardOnly, adLockReadOnly
    SSQL = vbNullString
    SSQL = "SELECT SETT FROM SETTORI WHERE MERCATO = '" & MERCATO_SEL & "'"
    CNSQL.Execute SSQL

    Do While Not RSSQL4.EOF
    TEST = RSSQL4!MERCATO
    TEST = RSSQL4!SETT
    RSSQL4.MoveNext
    Loop

    End Function

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

    Re: LOOP in rset based var (2000)

    Because you open a recordset on the full SETTORI table instead of on the SSQL string.
    You should NOT have a line

    CNSQL.Execute SSQL

    The line

    SSQL = vbNullString

    can be deleted, it is useless.

Posting Permissions

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