Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Microsoft Office > Access and Access VBA > Access VBA
|
Access VBA Discuss using VBA for Access programming.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Access VBA section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old March 11th, 2015, 02:47 AM
Registered User
 
Join Date: Mar 2015
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default VBA Runtime Error 1004 “Application-defined or Object-defined error”

I have code VBA code written in MS Access 2010 (.mbd file) to write data into an Excel file (.xls file). Below is the code to write data into that excel file. When you run this code, it always throws Error#1004 "Application-defined or Object-defined error". When you debug the code (F8) or run it (F5), it runs absolutely fine with out any issues. I am still not able to figure it out on what exactly the issue is. This code works fine when executed in MS Access 2007.

Below is thr code that's getting executed and when it fails, the focus is set on the 3rd last line of the code marked in double astriek mark.

Code:
Sub PopulateReport(appExcel As Object, testcam)

Dim Site As String, intRec As Integer, i As Integer, cnt As Integer, intRecSet As Integer, cntr As Integer
Dim F1 As String, F2 As String, F3 As String, F4 As String, F5 As String, F6 As String, F7 As String
Dim F8 As String, F9 As String, F10 As String, F11 As String, F12 As String, F13 As String, CAMDate As Date
Close
i = 0
cnt = 0
cntr = 0
Set cnn = CurrentProject.Connection

rec.Open "SELECT * FROM Site", cnn, adOpenStatic, adLockPessimistic
rec.MoveLast
rec.MoveFirst
intRec = rec.RecordCount
Do Until cnt = intRec
rec.MoveLast
rec.MoveFirst
    rec.Move cnt
    Site = rec(4)
    Select Case Site
        Case "Fort Worth"
            cntr = 0
            recset.Open "SELECT * FROM Employee", cnn, adOpenStatic, adLockPessimistic
            recset.MoveLast
            recset.MoveFirst
            intRecSet = recset.RecordCount
            appExcel.Application.Goto Reference:="START_FW_CL"
            Do Until cntr = intRecSet - 1
                appExcel.Selection.EntireRow.Copy
                appExcel.Selection.EntireRow.Insert
                cntr = cntr + 1
            Loop
            appExcel.Application.CutCopyMode = False
            appExcel.Application.Goto Reference:="START_FW2_CL"
            go = appExcel.Application.Range("START_FW2_CL")
            cntr = 1
             With appExcel.Worksheets("Accts. > Clearing").[START_FW2_CL]
                Do Until recset.EOF
                    **.Offset(cntr, 0) = recset(0)**
                    .Offset(cntr, 1) = recset(1)
                    .Offset(cntr, 2) = recset(2)
End Sub





Similar Threads
Thread Thread Starter Forum Replies Last Post
Application defined or Object defined error [email protected] Excel VBA 1 July 2nd, 2012 03:35 AM
Runtime Error on User Defined Aggregate Monchkrit BOOK: Professional Microsoft SQL Server 2008 Programming 1 August 6th, 2010 01:04 PM
Appl-defined or Object-defined error 1004 chp Excel VBA 3 April 4th, 2006 08:12 AM
object defined error piyushdabomb Excel VBA 1 February 1st, 2005 01:26 AM
Application-defined or object-defined error James Excel VBA 1 August 12th, 2003 11:50 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.