Tim
2013-12-11 08:28:08 UTC
I've hardcoded a query into a DAO recordset in MS Access. Once the recordset is opened, I open an Excel workbook that is a report template. Data from the query is placed into the spreadsheet using the loop below. The code runs fine for the first 1300 records accessed, then produces an error 1004 Application-Defined or Object Defined Error. I can then hit debug, and hit run and it continues without incident for another 1300 records. I have no idea why 1300 records is of any importance, but it almost always stops on the line
"'fill in Last Week data
.Range("P" & x).Select
ApXL.ActiveCell.Value = rst!LWeek_Inv
Here's a snippet of the loop code. Any help is appreciated.
Do Until rst.EOF
'check first rst!StartDate to make sure it matches BegDate
If rst!StartDate <> BegDate Then
Print #1, "There is no " & rst!StartDate & " record for " & rst![MFG Site] & "-" & rst![Item Number] & "-" & rst!Description & vbCrLf
GoTo BadDate1
End If
'populate first row for each SKU while on earliest record
.Range("A" & x).Select
ApXL.ActiveCell.Value = rst![MFG Site]
.Range("C" & x).Select
ApXL.ActiveCell.Value = rst!Family
.Range("D" & x).Select
ApXL.ActiveCell.Value = rst![Sub-Family]
.Range("E" & x).Select
ApXL.ActiveCell.Value = rst![Concentration]
.Range("H" & x).Select
ApXL.ActiveCell.Value = rst![Item Number]
.Range("I" & x).Select
ApXL.ActiveCell.Value = rst!Description
.Range("J" & x).Select
ApXL.ActiveCell.Value = rst![Safety Stock]
.Range("K" & x).Select
ApXL.ActiveCell.Value = rst!UOM
.Range("L" & x).Select
ApXL.ActiveCell.Value = rst!SPC
.Range("M" & x).Select
ApXL.ActiveCell.Value = rst!ASP
.Range("N" & x).Select
ApXL.ActiveCell.Value = rst![Item Status]
'copy over MRP row template for next item if not first record
If rst.AbsolutePosition > 0 Then
.Range("BS1:DU15").Select
ApXL.Selection.Copy
.Range("O" & x).Select
ApXL.Selection.PasteSpecial
End If
'fill in Last Week data
.Range("P" & x).Select
ApXL.ActiveCell.Value = rst!LWeek_Inv
y = x + 3
.Range("P" & y).Select
ApXL.ActiveCell.Value = rst!LWeek_Sched_Rcpts
y = y + 1
.Range("P" & y).Select
ApXL.ActiveCell.Value = rst!LWeek_Firm_Plan
y = y + 1
.Range("P" & y).Select
ApXL.ActiveCell.Value = rst!LWeek_Plan_Ord
y = y + 2
.Range("P" & y).Select
ApXL.ActiveCell.Value = rst!LWeek_Sales
y = y + 1
.Range("P" & y).Select
ApXL.ActiveCell.Value = rst!LWeek_Req
y = y + 1
.Range("P" & y).Select
ApXL.ActiveCell.Value = rst!LWeek_U_Fcst
y = y + 2
.Range("P" & y).Select
ApXL.ActiveCell.Value = rst!LWeek_Short_Dt