Question : Export 4 Queries to the same Worksheet

I have code to export 4 queries to the same workbook in 4 different worksheets. I'm using the TransferSpreadsheet method. I would like to change the code to put the results of the query in the same worksheet but I don't know how. I don't know if it's possible but I also would like to put 2 blank lines between each query result. The queries are:
1. qry_RN
2. qry_RN_Casual
3. qry_PT
4. qry_PT_Casual.

Thanks

Answer : Export 4 Queries to the same Worksheet

test this code
change filePathName accordingly

1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
Sub exp2XL()
Dim xlObj As Object, rs As DAO.recordset
Dim j As Integer, rowCnt As Integer, curRow As Integer
Dim filePathName As String
filePathName = "c:\myFolder\myExcel.xls"
Set xlObj = CreateObject("excel.application")

    xlObj.workbooks.Open filePathName

    With xlObj
        .worksheets(1).Select
        Set rs = CurrentDb.OpenRecordset("qry_RN")
        For j = 0 To rs.Fields.Count - 1
            .cells(1, j + 1).Value = rs(j).Name
        Next
        .Range("A2").copyfromrecordset rs
        
    rowCnt = .worksheets(1).usedrange.rows.Count
    
        Set rs = CurrentDb.OpenRecordset("qry_RN_Casual")
        For j = 0 To rs.Fields.Count - 1
            .cells(rowCnt + 3, j + 1).Value = rs(j).Name
        Next
        .Range("A" & rowCnt + 4).copyfromrecordset rs
    rowCnt = .worksheets(1).usedrange.rows.Count
    
        Set rs = CurrentDb.OpenRecordset("qry_PT")
        For j = 0 To rs.Fields.Count - 1
            .cells(rowCnt + 3, j + 1).Value = rs(j).Name
        Next
        .Range("A" & rowCnt + 4).copyfromrecordset rs
    rowCnt = .worksheets(1).usedrange.rows.Count
        
        Set rs = CurrentDb.OpenRecordset("qry_PT_Casual")
        For j = 0 To rs.Fields.Count - 1
            .cells(rowCnt + 3, j + 1).Value = rs(j).Name
        Next
        .Range("A" & rowCnt + 4).copyfromrecordset rs
    rowCnt = .worksheets(1).usedrange.rows.Count

        .activeworkbook.Save
    End With
    xlObj.Quit
    rs.Close
End Sub
Random Solutions  
 
programming4us programming4us