Writing Record to Excel Error

P

Paul

Hello,

I am encountering an Application-Defined error (1004) when I attempt to
write a record to Excel. I am building a recordset of say Customers and
validating each record by instantiating a Customer Class. I am using Property
Let statements to raise custom errors within the Customer Class property
which calls a procedure in a standard module to write the respective record
to an Excel error report. Otherwise, the valid record would be written to a
separate Excel profile report. I am using Access 2003 and DAO with a
reference set to Excel 11.0.

The code where the error occurrs from modErrorReport is:

' Access the worksheet's properties.
With mobjErrorWb.Worksheets(mintCurrWs)
.Cells(lngCurrErrRow, 1) = rsErrorRec.Fields(0) ' -----> Error
Number 1004 occurrs here.
.Cells(lngCurrErrRow, 2) = rsErrorRec.Fields(1)
.Cells(lngCurrErrRow, 3) = rsErrorRec.Fields(2)
End With

I set a reference to mobjErrorWb by using:

' Instantiate Excel object.
If fIsAppRunning("Excel") Then
Set objXlApp = GetObject(Class:="Excel.Application")
Else
Set objXlApp = CreateObject(Class:="Excel.Application")
End If ' End instantiating Excel objects.

' Copy Excel file from XLT to XLS file type.
FileCopy Source:=gstrcFilePath & gstrcErrorReportSourceFile, _
Destination:=gstrcFilePath & gstrcErrorReportDestinationFile

' Open the XLS file in a new window.
Application.FollowHyperlink Address:=gstrcFilePath & _
gstrcErrorReportDestinationFile, NewWindow:=True

Set mobjErrorWb = objXlApp.Workbooks(gstrcErrorReportDestinationFile)

The mobjErrorWb was set in modErrorReport from a separate procedure that was
called earlier to open the Error Report:

I hope I explained this enough. Any help is appreciated.

Thanks,

Paul
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top