Results 1 to 2 of 2

SQL Loop Problem Run-time error '3705':

Threaded View

  1. #1
    Registered User
    Join Date
    05-17-2011
    Location
    Manila, Philippines
    MS-Off Ver
    Excel 2003
    Posts
    2

    Unhappy SQL Loop Problem Run-time error '3705':

    hello! i'm just new in here.. I started practicing vba programming since yesterday... pls help me on my problem...

    I've already connected my records at ms access.. the macro i made is only runnable at 1st row of my table.. so i made a loop to fill up the next rows with data..

    but i got these error..

    Run-time error '3705':
    Operation is not allowed when the object is open

    here's my code:
    ________________________________________
    Sub PriceListComputation()
    
    Dim con As New ADODB.Connection
    Dim rs As New ADODB.Recordset
    
    Dim row As Integer
    
    con.ConnectionString = "DBQ=C:\PriceList.mdb; " & "DRIVER={Microsoft Access Driver (*.mdb)}"
    
    con.Open
    
    Set rs.ActiveConnection = con
    
    row = ActiveSheet.UsedRange.Rows.Count
    
    For moveRow = 7 To (row - 22)       'here's the loop i made where i got error.
    
    rs.Open "SELECT * FROM Uniforms WHERE item_name = '" & ActiveSheet.Cells (moveRow, 2) & "'"
    
    Next
    
    startRow = 7          'this is the loop on the first row of my table, but didn't work at next
    Do Until rs.EOF
        Cells(startRow, 2) = rs.Fields(2).Value
        Cells(startRow, 7) = rs.Fields(3).Value
        Cells(startRow, 6) = rs.Fields(5).Value
        rs.MoveNext
        startRow = startRow + 1
    Loop
    
    rs.Close
    Set rs = Nothing
    
    con.Close
    Set con = Nothing
    
    End Sub
    _________________________________________

    I got the logic but i don't know how to code it properly..

    still got many questions to ask.. but my priority was this one.. help me plz.. thanks in advance
    Last edited by romperstomper; 05-18-2011 at 03:01 AM. Reason: add code tags.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1