Hello all, thanks to Dennisk and Paul, I am able to move through my recordset and create a directory with each individual name. Now, I am attempting to "FileCopy" an excel template into each directory with the directories name.xls------got this fine.
Now I am attempting to copy and paste each individual's records by looping through the recordset RST1 and place that information into the appropriate directory/directory.xls file; close; and then save all workbooks.
Could someone point me in the right direction? Currenlty, the code is dumping all of the information into my first directory, and doing nothing for the rest of my recordsets.
Do I need another loop here? Example Do Until EOF RST1?
Here is the code:
Dim rst As DAO.RecordSet
Dim DIRName As String
Dim folder As String
Dim Dir As String
Dim strnewname As String
Dim stroldname As String
Dim Pause As Boolean
Dim xlApp As Excel.Application
Dim xlBook As Excel.Workbook
Dim xlSheet As Excel.Worksheet
Dim blnExcelOpen As Boolean
Dim strMacro As String
Dim mysheetpath As String
Dim rst1 As DAO.RecordSet
Dim objdb As Database
Dir = Me.Combo19
folder = "H:\" & Dir & "\"
'DoCmd.OpenForm "frmWait"
'DoCmd.RepaintObject acForm, "frmWait"
Set rst = CurrentDb.OpenRecordset("tblofficers")
Set rst1 = CurrentDb.OpenRecordset("tbl_Q1")
Do Until rst.EOF
DIRName = folder & rst!OFFICERS_NAME
stroldname = "H:\Asset Verification Template.xls"
strnewname = folder & rst!OFFICERS_NAME & "\" & rst!OFFICERS_NAME & ".xls"
' Processing each officer and creating a directory
MkDir DIRName
Sleep 10
FileCopy stroldname, strnewname
'Name stroldname As strnewname
Sleep 10
mysheetpath = strnewname
blnExcelOpen = IsExcelRunning()
If (blnExcelOpen) Then
Set xlApp = GetObject(, "Excel.Application")
Else
Set xlApp = CreateObject("Excel.Application")
End If
Set xlBook = xlApp.Workbooks.Open(mysheetpath, False, False)
Set xlSheet = xlBook.Worksheets("Sheet1")
'Transfer the data to Excel
xlSheet.Range("A2:r10000").ClearContents
xlSheet.Range("A2:r10000").CopyFromRecordset rst1
'rst1.Close
xlBook.Save
' back to the top...
xlApp.CutCopyMode = False
rst.MoveNext
Loop
' if we started Excel, then close it now…
If (Not blnExcelOpen) Then
xlApp.Quit
End If
' clean up...
Set rst1 = Nothing
Set objdb = Nothing
Set xlSheet = Nothing
Set xlBook = Nothing
Set xlApp = Nothing
Now I am attempting to copy and paste each individual's records by looping through the recordset RST1 and place that information into the appropriate directory/directory.xls file; close; and then save all workbooks.
Could someone point me in the right direction? Currenlty, the code is dumping all of the information into my first directory, and doing nothing for the rest of my recordsets.
Do I need another loop here? Example Do Until EOF RST1?
Here is the code:
Dim rst As DAO.RecordSet
Dim DIRName As String
Dim folder As String
Dim Dir As String
Dim strnewname As String
Dim stroldname As String
Dim Pause As Boolean
Dim xlApp As Excel.Application
Dim xlBook As Excel.Workbook
Dim xlSheet As Excel.Worksheet
Dim blnExcelOpen As Boolean
Dim strMacro As String
Dim mysheetpath As String
Dim rst1 As DAO.RecordSet
Dim objdb As Database
Dir = Me.Combo19
folder = "H:\" & Dir & "\"
'DoCmd.OpenForm "frmWait"
'DoCmd.RepaintObject acForm, "frmWait"
Set rst = CurrentDb.OpenRecordset("tblofficers")
Set rst1 = CurrentDb.OpenRecordset("tbl_Q1")
Do Until rst.EOF
DIRName = folder & rst!OFFICERS_NAME
stroldname = "H:\Asset Verification Template.xls"
strnewname = folder & rst!OFFICERS_NAME & "\" & rst!OFFICERS_NAME & ".xls"
' Processing each officer and creating a directory
MkDir DIRName
Sleep 10
FileCopy stroldname, strnewname
'Name stroldname As strnewname
Sleep 10
mysheetpath = strnewname
blnExcelOpen = IsExcelRunning()
If (blnExcelOpen) Then
Set xlApp = GetObject(, "Excel.Application")
Else
Set xlApp = CreateObject("Excel.Application")
End If
Set xlBook = xlApp.Workbooks.Open(mysheetpath, False, False)
Set xlSheet = xlBook.Worksheets("Sheet1")
'Transfer the data to Excel
xlSheet.Range("A2:r10000").ClearContents
xlSheet.Range("A2:r10000").CopyFromRecordset rst1
'rst1.Close
xlBook.Save
' back to the top...
xlApp.CutCopyMode = False
rst.MoveNext
Loop
' if we started Excel, then close it now…
If (Not blnExcelOpen) Then
xlApp.Quit
End If
' clean up...
Set rst1 = Nothing
Set objdb = Nothing
Set xlSheet = Nothing
Set xlBook = Nothing
Set xlApp = Nothing