Dim lngColumn As Long, result As Integer
Dim xlx As Object, xlw As Object, xls As Object, xlc As Object
Dim db As DAO.Database, rst As DAO.Recordset
Dim svChartPath As String, msg As String
Dim blnCanCheckout As Boolean, blnWeCheckedOut As Boolean
'some code before here, then...
'open an Excel application...
Set xlx = CreateObject("Excel.Application")
xlx.ScreenUpdating = False
xlx.DisplayAlerts = False
xlx.Visible = False
'... now test to see if we can check out the workbook (exlusive use)
blnCanCheckout = xlx.Workbooks.CanCheckOut(svChartPath)
If blnCanCheckout Then
Set xlw = xlx.Workbooks.Open(svChartPath)
xlx.Workbooks.CheckOut svChartPath
'if previous successful, we should store this in case of interruption
Pause (2) 'allow time for server to open workbook before writing data
Set xls = xlw.Worksheets("DATA")
'delete data in the ranges in case fewer records are being entered
With xls
.Range("DailyCountRange").ClearContents
.Range("DateRange").ClearContents
End With
Set xlc = xls.Range("A6") ' this is the first cell into which data goes
rst.MoveFirst
For lngColumn = 0 To rst.Fields.count - 1
'enable next to write data column headers
''xlc.Offset(0, lngColumn).value = rst.Fields(lngColumn).Name
Next lngColumn
''Set xlc = xlc.Offset(1, 0)'offset IF the headers were written
Set xlc = xlc.Offset(0, 0) 'otherwise, no offset
' write data to worksheet
Do While rst.EOF = False
For lngColumn = 0 To rst.Fields.count - 1
xlc.Offset(0, lngColumn).value = rst.Fields(lngColumn).value
Next lngColumn
rst.MoveNext
Set xlc = xlc.Offset(1, 0)
Loop
MsgBox "Data push was successful!"
With Forms!frmWait
.lblMsg.Caption = "Workbook will now be saved, checked in and closed."
.Repaint
End With
Pause 3
xlw.Save 'save the changes
xlw.CheckIn svChartPath 'check in the workbook
blnWeCheckedOut = False 'record that the workbook is no longer checked out
End If
'more code 'til the end