I have been using the code below for several months now with no problem. But suddenly this morning I get an Overflow -- 6 error. The code is below and it seems to be erroring out at the "For y = RowStart To rst.RecordCount" part. I'm not sure what is causing this.
Private Sub Command17_Click()
On Error GoTo CloseRecords
Dim objexcel As Excel.Application
Dim wkb As Excel.Workbook
Dim wks As Excel.Worksheet
Dim rst As DAO.Recordset
Dim db As DAO.Database
Dim fld As DAO.Field
Dim x As Integer
Dim y As Integer
Dim rcount
Const fcount = 11
Dim RowStart As Integer
Set db = CurrentDb
Set rst = db.OpenRecordset("Loss Prevention Data", dbOpenDynaset)
rst.MoveLast
rst.MoveFirst
Set objexcel = CreateObject("excel.application")
objexcel.Visible = False
Set wkb = objexcel.Workbooks.Open("\\NCMAIN03\USERS\COMMON_H R\#HRIS\PLATEAU REPORTING\LP_Compliance_Report\LP_Compliance_Repor t_Template.xls")
Set wks = wkb.Worksheets("Compliance Detail")
'end test segment
RowStart = 1 ' renumbers rows
For y = RowStart To rst.RecordCount
For x = 1 To fcount
wks.Cells(y + 1, x).Value = rst.Fields(x - 1).Value
Next x
rst.MoveNext
Next y
wks.Cells.EntireColumn.AutoFit
Set wks = wkb.Worksheets("Dist %")
Set rst = db.OpenRecordset("Dist%Complete", dbOpenDynaset)
rst.MoveLast
rst.MoveFirst
RowStart = 1 ' renumbers rows
For y = RowStart To rst.RecordCount
For x = 1 To fcount - 9
wks.Cells(y + 1, x).Value = rst.Fields(x - 1).Value
Next x
rst.MoveNext
Next y
wks.Cells.EntireColumn.AutoFit
wks.SaveAs "\\NCMAIN03\USERS\COMMON_HR\#HRIS\PLATEAU REPORTING\LP_Compliance_Report\LP_Compliance_Repor t_" & Format(Now(), "MMDDYYYY") & ".xls"
objexcel.Dialogs.Application.ActiveWorkbook.Save
objexcel.Workbooks.Close
objexcel.UserControl = True
objexcel.Quit
Exit_MyProc:
rst.Close
Set wks = Nothing
Set objexcel = Nothing
Set rst = Nothing
Set db = Nothing
Exit Sub
CloseRecords:
MsgBox Err.Description & " -- " & Err.Number
Resume Exit_MyProc
Resume
End Sub



