Problem with export code

Skip Bisconer

Who Me?
Local time
Today, 08:57
Joined
Jan 22, 2008
Messages
285
I had this working fine until I had to add another column of data to the spreadsheet. Now I get and error 3265 Itme not found in this collection. When I click OK I get Error 424 Object required. It seems to die at the End With statement. This particular query only has two lines of data and they do get to the spreadsheet in the correct manner.

For the life of me I can't figure what is different from the first version which worked properly. This is my code, I would appreciate another pair of eyes looking at it cause mine are bloodshot. Thanks for looking.
Code:
Private Sub Bisconer_Click()
On Error GoTo ErrorHandler
Dim objXL As Object
Dim xlWB As Object
Dim xlWS As Object
Set objXL = CreateObject("Excel.Application")
objXL.Visible = True
Set xlWB = objXL.Workbooks.Open("C:\Amex\CurrentChargesBisconer.xls")
Set xlWS = xlWB.Worksheets("CurrentCharges")
xlWS.Range("A2").Select
Dim db As Database
Dim rs As Recordset
Dim i As Integer
Set db = CurrentDb
Set rs = db.OpenRecordset("CurrentCharges11152", , dbOpenDynamic)
rs.MoveFirst
i = 2
Do Until rs.EOF
 
  With xlWS
  ' assign records to specific cells
  .Range("A" & i).Value = rs.Fields("GLExpense").Value
  .Range("B" & i).Value = rs.Fields("GLCode").Value
  .Range("C" & i).Value = rs.Fields("VC").Value
  .Range("D" & i).Value = rs.Fields("Loc").Value
  .Range("E" & i).Value = rs.Fields("Customer").Value
  .Range("F" & i).Value = rs.Fields("LastName").Value
  .Range("G" & i).Value = rs.Fields("FirstName").Value
  .Range("H" & i).Value = rs.Fields("CardNo").Value
  .Range("I" & i).Value = rs.Fields("Date").Value
  .Range("J" & i).Value = rs.Fields("BusinessType").Value
  .Range("K" & i).Value = rs.Fields("Commodity").Value
  .Range("L" & i).Value = rs.Fields("SupplierName").Value
  .Range("M" & i).Value = rs.Fields("Amount").Value
  .Range("N" & i).Value = rs.Fields("Department").Value
 
 
 
  End With
i = i + 1
rs.MoveNext
Loop
 rs.Close
 db.Close
 Exit Sub
ErrorHandler:
    ' Display error information.
    MsgBox "Error number " & Err.Number & ": " & Err.Description
    ' Resume with statement following occurrence of error.
    Resume Next
 
End Sub
 
Comment out

On Error GoTo ErrorHandler

and run it, which should give you the option to debug and take you to the offending line.
 
Thanks Paul, I will do that.
 

Users who are viewing this thread

Back
Top Bottom