MikeAuz1979
Programmer
Hi Using Access 2000 and excel 2003 I'm trying to write a sub that will basically copy and paste data from three access tables to three different excel tabs on a excel template. (Range A2 on all 3 tabs)
So the below is as far as I have got and I get the error 'Can't assign to array' on the 'RstArray = ' line when I try to first run the code.
Anyone have any ideas?
Thanks for any help!
Code Start-----
Sub test()
Dim con As New ADODB.Connection
Dim rst As New ADODB.Recordset
Dim RstArray(2, 3)
con.ConnectionString = CurrentProject.Connection
con.Open
Set rst.ActiveConnection = con
Set acapp = CreateObject("Excel.Application")
acapp.displayalerts = False
acapp.Workbooks.Open ("C:\Template.xlt")
acapp.Visible = True
RstArray = Array("tblAll", "AllData", "tblDefault", "DefaultData", "tblContractFinal", "ContractData")
For i = 0 To 2
rst.Source = "SELECT * from " & RstArray(i, 0)
rst.Open
With acapp.worksheets(TabArray(i, 1)).range("A2")
.CopyFromRecordset rst
End With
rst.Close
Next
Set con = Nothing
End Sub
Code End-----
So the below is as far as I have got and I get the error 'Can't assign to array' on the 'RstArray = ' line when I try to first run the code.
Anyone have any ideas?
Thanks for any help!
Code Start-----
Sub test()
Dim con As New ADODB.Connection
Dim rst As New ADODB.Recordset
Dim RstArray(2, 3)
con.ConnectionString = CurrentProject.Connection
con.Open
Set rst.ActiveConnection = con
Set acapp = CreateObject("Excel.Application")
acapp.displayalerts = False
acapp.Workbooks.Open ("C:\Template.xlt")
acapp.Visible = True
RstArray = Array("tblAll", "AllData", "tblDefault", "DefaultData", "tblContractFinal", "ContractData")
For i = 0 To 2
rst.Source = "SELECT * from " & RstArray(i, 0)
rst.Open
With acapp.worksheets(TabArray(i, 1)).range("A2")
.CopyFromRecordset rst
End With
rst.Close
Next
Set con = Nothing
End Sub
Code End-----