Posted to microsoft.public.excel.programming
|
|
Excel 2003 with SP" 1004 error
Add Option Explicit at the beginning of the code and compile. That may help
you some. If that doesn't work, come back. I don't work with ADODB
connections so can't say for sure what's going on.
"eggpap" wrote:
Help me please.
In a workbook I have the following sub that retrieves data from an
Access table into tha "RFest" range of the "festivi" sheet. I have no
error using Office 2003 Professional with SP3. I get, instead, the
following error with Office 2003 Professional SP2
Applicatione or object defined error/1004
on the statements
TargetRange.cells(1, intColIndex+1).Value =
TargetRange.cells(2, 1).CopyFromRecordset rs
However, I cannot to update to SP£ since my Company has not released it
since incompatible with other applications.
Any tip to solve such error without the SP3 upgrade?
Sub ADOImport(TableName As String, drecup As String)
Dim cn As ADODB.Connection, rs As ADODB.Recordset, appath As
String
Dim intColIndex As Integer,TargetRange As Range, ws as worksheet
Dim CID As Long, SQLstr As String, anno As Integer
On Error GoTo err_hnd
set ws=Worksheets("Festivi")
set TargetRange=ws.range("RFest")
Call ScopriRighe
appath = ThisWorkbook.Path & "\"
CID = Range("1Trim!H56").Value
anno = Range("1Trim!AO1").Value
' apre il database
Set cn = New ADODB.Connection
With cn
.Provider = "Microsoft.jet.OLEDB.4.0"
.Properties("Data Source") = appath & "festivi.mdb"
.Properties("Jet OLEDB:Database Password") = PWORD
.Open
End With
Set rs = New ADODB.Recordset
SQLstr = ..omessa per semplicitÃ*
With rs
.Open SQLstr, cn, , , adCmdText
For intColIndex = 0 To rs.Fields.Count - 1 ' nomi dei campi
' l'errore avviene sull'istruzione seguente
' Errore definito dall'applicazione o dall'oggetto /1004
TargetRange.cells(1, intColIndex+1).Value =
rs.Fields(intColIndex).Name
Next
TargetRange.cells(2, 1).CopyFromRecordset rs
End With
rs.Close
Set rs = Nothing
cn.Close
Set cn = Nothing
Set TargetRange = Nothing
set ws=Nothing
Exit Sub
err_hnd:
MsgBox Err.Description & "/" & Err.Number & " Sub ADOImport"
Resume Next
End Sub
Thanks, Emiliano
--
eggpap
Excel 2003 on Vista HP System - can use VBA
------------------------------------------------------------------------
eggpap's Profile: http://www.thecodecage.com/forumz/member.php?userid=90
View this thread: http://www.thecodecage.com/forumz/sh...ad.php?t=77743
|