简体   繁体   中英

Excel VBA Data Export

Here is the code I have written to export data from access to excel but can not see any records.

Sub copyFromRecordset()

    Set conn = New ADODB.Connection
    Set wipData = New ADODB.Recordset

    conn.ConnectionString = conStr
    conn.Open

    With wipData
        .ActiveConnection = conn
        .Source = "WipBin"
        .LockType = adLockReadOnly
        .CursorType = adOpenForwardOnly
        .Open
    End With

    Worksheets.Add
    Range("A2").copyFromRecordset wipData

    wipData.Close
    conn.Close

End Sub

please advice

Why not Simply use the DoCmd.TransferSpreadsheet method

DoCmd.TransferSpreadsheet acExport, , "TABLE name", "filelocation"

https://msdn.microsoft.com/en-us/vba/access-vba/articles/acspreadsheettype-enumeration-access

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM