Sub AppendToSpreadsheet()
On Error GoTo HandleError
' Define Access and Excel object variables
Dim objXLApp As Object
Set objXLApp = CreateObject("Excel.Application")
Dim objXLBook As Excel.Workbook
Dim objResultsSheet As Excel.Worksheet
Dim db As DAO.Database
Dim rs As DAO.Recordset
Dim RowVal As Integer
Dim ColVal As Integer
Dim NextFriday As Date
NextFriday = Replace(Format(Date + 8 - Weekday(Date, vbFriday), "mm/dd/yy"), "/", "-")
MyFileName = "8382 Melrose Webform " & NextFriday & ".xls"
MsgBox MyFileName
Set db = CurrentDb
Set rs = db.OpenRecordset("Web_Form")
conPath = CurrentProject.path
' Open Excel sheet as an Excel Object
Set objXLApp = Excel.Application
Set objXLBook = objXLApp.Workbooks.Open("C:\Work Files\Uploads\MyFileName")
Set objResultsSheet = objXLBook.Worksheets("Sheet1")
RowVal = 1
ColVal = 1
' Find the last row of data
Do While Not objResultsSheet.Cells(RowVal, ColVal) = Empty
RowVal = RowVal + 1
Loop
' Write data from Access query to Spreadsheet
Do While Not rs.EOF
'objResultsSheet.Range(Cells(RowVal, ColVal + 0), Cells(RowVal, ColVal + 0)) = rs!Request_Type
objResultsSheet.Range(Cells(RowVal, ColVal + 0), Cells(RowVal, ColVal + 0)) = rs!Request_Type
objResultsSheet.Range(Cells(RowVal, ColVal + 1), Cells(RowVal, ColVal + 1)) = rs!DISTRICT
objResultsSheet.Range(Cells(RowVal, ColVal + 2), Cells(RowVal, ColVal + 2)) = rs!TechID
objResultsSheet.Range(Cells(RowVal, ColVal + 3), Cells(RowVal, ColVal + 3)) = rs!Request_Date
objResultsSheet.Range(Cells(RowVal, ColVal + 4), Cells(RowVal, ColVal + 4)) = rs!Enterprise_ID
objResultsSheet.Range(Cells(RowVal, ColVal + 5), Cells(RowVal, ColVal + 5)) = rs!Upload_Codes
objResultsSheet.Range(Cells(RowVal, ColVal + 6), Cells(RowVal, ColVal + 6)) = rs!EFFECTIVE_DATE
objResultsSheet.Range(Cells(RowVal, ColVal + 7), Cells(RowVal, ColVal + 7)) = rs!Tech_District_Info
objResultsSheet.Range(Cells(RowVal, ColVal + 8), Cells(RowVal, ColVal + 8)) = rs!Tech_Specialty
objResultsSheet.Range(Cells(RowVal, ColVal + 9), Cells(RowVal, ColVal + 9)) = rs!PDC
objResultsSheet.Range(Cells(RowVal, ColVal + 10), Cells(RowVal, ColVal + 10)) = rs!State
objResultsSheet.Range(Cells(RowVal, ColVal + 11), Cells(RowVal, ColVal + 11)) = rs!SEARSORAE
objResultsSheet.Range(Cells(RowVal, ColVal + 12), Cells(RowVal, ColVal + 12)) = rs!C_U_S
RowVal = RowVal + 1
rs.MoveNext
Loop
' Save and close spreadsheet
objXLBook.Save
objXLBook.Close
MsgBox "Done!"
ProcDone:
On Error Resume Next
' Let's clean up our act
Set qdf = Nothing
Set db = Nothing
Set rs = Nothing
Set objResultsSheet = Nothing
Set objXLBook = Nothing
Set objXLApp = Nothing
ExitHere:
Exit Sub
HandleError:
MsgBox Err.Description, vbExclamation, _
"Error " & Err.Number
Resume ProcDone
End Sub