+ Reply to Thread
Results 1 to 3 of 3

troubles not bringing in the first row of a ado query to another spreadsheet...

  1. #1
    Registered User
    Join Date
    05-19-2004
    Posts
    2

    troubles not bringing in the first row of a ado query to another spreadsheet...

    ...troubles not bringing in the first row of a ado query...

    this code works well, BUT I have found that this code doesn’t copy in the first row of the recordset

    ???


    Code:


    Do Until filenameI = ""

    strSourceFile = PATH & filenameI

    mytab = Mid(filenameI, 1, InStr(1, filenameI, ".") - 1)

    strsql = "SELECT * FROM [" & mytab & "$];"

    'connection...

    Set cn = New ADODB.Connection

    'open connection...

    cn.Open "DRIVER={Microsoft Excel Driver (*.xls)};DriverId=790;ReadOnly=True;" & _

    "DBQ=" & strSourceFile & ";"

    'recordset

    Set rs = New ADODB.Recordset

    'open rs

    rs.Open strsql, cn, adOpenForwardOnly, adLockReadOnly, adCmdText

    'copy in rs

    Selection.End(xlDown).Select

    ActiveCell.Offset(1, 0).Select

    ActiveCell.CopyFromRecordset rs

    ‘clean-up

    rs.Delete

    rs.Close

    filenameI = Dir()

    Loop

    thank you...

  2. #2
    K Dales
    Guest

    RE: troubles not bringing in the first row of a ado query to another s

    I have never tried a CopyFromRecordSet with adOpenForwardOnly; perhaps that
    is the issue (Open command reads first record; so the CopyFromRecordset can
    only move forward from there??? Just speculating). Try adOpenDynamic and
    see if that helps.
    --
    - K Dales


    "mjschukas" wrote:

    >
    > ...troubles not bringing in the first row of a ado query...
    >
    > this code works well, BUT I have found that this code doesn’t copy in
    > the first row of the recordset
    >
    > ???
    >
    >
    > Code:
    >
    >
    > Do Until filenameI = ""
    >
    > strSourceFile = PATH & filenameI
    >
    > mytab = Mid(filenameI, 1, InStr(1, filenameI, ".") - 1)
    >
    > strsql = "SELECT * FROM [" & mytab & "$];"
    >
    > 'connection...
    >
    > Set cn = New ADODB.Connection
    >
    > 'open connection...
    >
    > cn.Open "DRIVER={Microsoft Excel Driver
    > (*.xls)};DriverId=790;ReadOnly=True;" & _
    >
    > "DBQ=" & strSourceFile & ";"
    >
    > 'recordset
    >
    > Set rs = New ADODB.Recordset
    >
    > 'open rs
    >
    > rs.Open strsql, cn, adOpenForwardOnly, adLockReadOnly, adCmdText
    >
    > 'copy in rs
    >
    > Selection.End(xlDown).Select
    >
    > ActiveCell.Offset(1, 0).Select
    >
    > ActiveCell.CopyFromRecordset rs
    >
    > ‘clean-up
    >
    > rs.Delete
    >
    > rs.Close
    >
    > filenameI = Dir()
    >
    > Loop
    >
    > thank you...
    >
    >
    > --
    > mjschukas
    > ------------------------------------------------------------------------
    > mjschukas's Profile: http://www.excelforum.com/member.php...fo&userid=9695
    > View this thread: http://www.excelforum.com/showthread...hreadid=394584
    >
    >


  3. #3
    Registered User
    Join Date
    05-19-2004
    Posts
    2

    thank you...

    thank you...!

    i will try...

    thanks!


    Quote Originally Posted by K Dales
    I have never tried a CopyFromRecordSet with adOpenForwardOnly; perhaps that
    is the issue (Open command reads first record; so the CopyFromRecordset can
    only move forward from there??? Just speculating). Try adOpenDynamic and
    see if that helps.
    --
    - K Dales


    "mjschukas" wrote:

    >
    > ...troubles not bringing in the first row of a ado query...
    >
    > this code works well, BUT I have found that this code doesn’t copy in
    > the first row of the recordset
    >
    > ???
    >
    >
    > Code:
    >
    >
    > Do Until filenameI = ""
    >
    > strSourceFile = PATH & filenameI
    >
    > mytab = Mid(filenameI, 1, InStr(1, filenameI, ".") - 1)
    >
    > strsql = "SELECT * FROM [" & mytab & "$];"
    >
    > 'connection...
    >
    > Set cn = New ADODB.Connection
    >
    > 'open connection...
    >
    > cn.Open "DRIVER={Microsoft Excel Driver
    > (*.xls)};DriverId=790;ReadOnly=True;" & _
    >
    > "DBQ=" & strSourceFile & ";"
    >
    > 'recordset
    >
    > Set rs = New ADODB.Recordset
    >
    > 'open rs
    >
    > rs.Open strsql, cn, adOpenForwardOnly, adLockReadOnly, adCmdText
    >
    > 'copy in rs
    >
    > Selection.End(xlDown).Select
    >
    > ActiveCell.Offset(1, 0).Select
    >
    > ActiveCell.CopyFromRecordset rs
    >
    > ‘clean-up
    >
    > rs.Delete
    >
    > rs.Close
    >
    > filenameI = Dir()
    >
    > Loop
    >
    > thank you...
    >
    >
    > --
    > mjschukas
    > ------------------------------------------------------------------------
    > mjschukas's Profile: http://www.excelforum.com/member.php...fo&userid=9695
    > View this thread: http://www.excelforum.com/showthread...hreadid=394584
    >
    >

+ Reply to Thread

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