VBA CODE Command Button to output table records into seperate excel sheets

Clete

Board Regular
Joined
Sep 5, 2014
Messages
62
Im extremely stuck. I found some code and wrote the shell of what im trying to do. In the Do Until part I need to fill it in. Let's say I have 2 records in the table called tmpCheckQueue with the fields Amount and CheckNo. How do I code the loop to place Amount into A1 and CheckNo into B1 from the first record into Sheet1 and then do the same for record 2 into Sheet2. I know once I can get this part to work I have everything Ill need to finish and ive been trying hard find examples, I think this situation is a bit rare. Thanks for all the help it's greatly appreciated.






Private Sub cmdPrintChecks_Click()
Dim ExcelApp As Excel.Application
Dim ExcelWorkbook As Excel.Workbook
Dim ExcelSheet As Excel.Worksheet
Dim db As DAO.Database
Dim rs As DAO.Recordset
Dim sPath As String
Dim i As Integer

Set ExcelApp = CreateObject("Excel.Application")
Set ExcelWorkbook = ExcelApp.Workbooks.Add
Set db = CurrentDb
Set rs = db.OpenRecordset("tmpCheckQueue")



sPath = "C:\Checks"

rs.MoveFirst

i = 1

Do Until rs.EOF

Set ExcelSheet = ExcelWorkbook.Worksheets(i)




rs.MoveNext
i = i + 1
Loop

rs.Close
Set rs = Nothing
Set db = Nothing
Set ExcelApp = Nothing
Set ExcelWorkbook = Nothing
Set ExcelSheet = Nothing



End Sub
 

Excel Facts

Easy bullets in Excel
If you have a numeric keypad, press Alt+7 on numeric keypad to type a bullet in Excel.

Forum statistics

Threads
1,203,522
Messages
6,055,893
Members
444,832
Latest member
Kauri

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top