Hi i have two modules; both contain the code below to insert entries into an excel spreadsheet; this code works for both modules separately. However when i run a sub that runs both modules one after another, the 1st modules entries are put on the spreadsheet but the second modules entries are not. Can anyone tell me why this is please?
Set rs3 = db.OpenRecordset("Select [tblWorking].STU_ID, [tblWorking].STU_FORENAME, [tblWorking].STU_SURNAME, [tblWorking].STU_TU_CODE From [tblWorking] Where tblWorking.STU_TU_CODE is not null ")
Dim objXL As Excel.Application 'Modify spreadsheet that informs SIS of allocation
Dim objWkb As Object
On Error Resume Next
Set objXL = GetObject(, "Excel.Application")
Set objWkb = objXL.Application.ActiveWorkbook
Const xlDown = -4121
With objXL.ActiveSheet.Range("a1").End(xlDown).Offset(1, 0)
.CopyFromRecordset rs3
End With
If objXL Is Nothing Then
Set objXL = CreateObject("Excel.application")
Dim objws As Excel.Worksheet
Set objWkb = objXL.Workbooks.add
Set objws = objWkb.Worksheets.add
With objws
objws.Range("A1").CopyFromRecordset rs3
End With
End If
objXL.Visible = True
objXL.WindowState = xlMinimized
Set objXL = Nothing
Set rs3 = db.OpenRecordset("Select [tblWorking].STU_ID, [tblWorking].STU_FORENAME, [tblWorking].STU_SURNAME, [tblWorking].STU_TU_CODE From [tblWorking] Where tblWorking.STU_TU_CODE is not null ")
Dim objXL As Excel.Application 'Modify spreadsheet that informs SIS of allocation
Dim objWkb As Object
On Error Resume Next
Set objXL = GetObject(, "Excel.Application")
Set objWkb = objXL.Application.ActiveWorkbook
Const xlDown = -4121
With objXL.ActiveSheet.Range("a1").End(xlDown).Offset(1, 0)
.CopyFromRecordset rs3
End With
If objXL Is Nothing Then
Set objXL = CreateObject("Excel.application")
Dim objws As Excel.Worksheet
Set objWkb = objXL.Workbooks.add
Set objws = objWkb.Worksheets.add
With objws
objws.Range("A1").CopyFromRecordset rs3
End With
End If
objXL.Visible = True
objXL.WindowState = xlMinimized
Set objXL = Nothing