I fill a recordset from a simple query with ADO and when manually printing it's all good and clear but when i try to transfer the Recordset in the Sheet's table only 3 columns are filled out of 4.
That's the only method i use and always worked. I changed Range, pointed outside a table, used a single cell and a bigger range than what my query will return. All I got was 3 columns.
Dim ws As Worksheet
Set ws = ThisWorkbook.Worksheets(1)
Dim conn As Object
Set conn = openCon 'other function I assure to works
Dim rst As Object
Dim query As String
Set rst = CreateObject("ADODB.RECORDSET")
'I don't think the problem is here but i really don't know what it could be
If ws.Range("tabArts").Rows.Count > 1 Then
ws.Range("tabArts").Rows.Delete
Else
ws.Range("tabArts").ClearContents
End If
query = ""
query = query & "SELECT art.code , "
query = query & " art.descr, "
query = query & " Sum (tb1.qty) 'Qty', "
query = query & " tb1.serials "
'serials is defined as NON NULL, so it's an empty string if not written
query = query & "FROM tb1 "
query = query & " LEFT OUTER JOIN articles art "
query = query & " ON tb1.idart = art.id "
query = query & "GROUP BY code, Descr, serials"
'This query return a full 4 columns table with 15 rows
rst.activeconnection = conn
rst.Open query
ws.Range("tabArts").CopyFromRecordset rst
'tabArts is a table with same query's headers
rst.Close
conn.Close
Use below code before rst.open
rst.CursorLocation = adUseClient
rst.CursorType = adOpenStatic
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.