E
eggpap
I use a wb as input interface to save the data on some mdb files at th
end of the Excel session. The retrieving or saving data task from Acces
to Excel and viceversa, however, is very slow so I am trying to get
faster routine.
Currently, to retrieve the data, I read ADO recordsets and assign th
fields value to the target ranges. To save to Access, viceversa,
append/update validating the recordset fields with the cell values.
To retrieve (and similarly to save) the data, I have tested th
following routine: since the Access tables are transposed respect to th
ranges I need to populate, I import the table on a sheet by th
CopyFromRecordset method, select the data range, copy the selection an
PasteSpecial it transposed on the range I need. *Surprisingly the resul
I get is slower than that currently used!!*.
Here is the routine I use to Retrieve the Data form Access...
Sub RetrevingData(month as long)
'
' here other not interesting instructions
'
M = CLng(month)
ID = ID_filter
Year = Range("1Trim!AO1").Value
Set cn = New ADODB.Connection
With cn
.Provider = "Microsoft.jet.OLEDB.4.0"
.Properties("Data Source") = appath & "people.mdb"
.Properties("Jet OLEDBatabase Password") = PWORD
.Open
End With
Set rs = New ADODB.Recordset
'SQLstr = "SELECT tb1.*, Year([Data1]) AS Y, Month([Data1]) AS M
tb1.CID FROM tb1 WHERE " _
'& "(((Year([Data1]))=" & Year & ") AND ((Month([Data1]))=" & Mont
& " ) AND ((tb1.CID)=" & ID & "));"
SQLstr = "SELECT tb1.T, tb1.V, tb1.A, tb1.P, tb1.S, tb1.R " _
& "FROM tb1 WHERE (((Year([Data1]))=" & Year & ") AN
((Month([Data1]))=" & M & ") AND ((tb1.CID)=" & ID & "));"
With rs
.Open SQLstr, cn, 3, 3, adCmdText
Sheets("LoadData").Activate
Sheets("LoadData").Select
Range("DataZone").Select
Range("DataZone").Clear
Range("LoadData!A1").CopyFromRecordset rs
Select Case M
Case 1, 4, 7, 10
Call CopYAndTranspose(Range("DataZone"), M, "C6")
Case 2, 5, 8, 11
Call CopyAbdTranspose(Range("DataZone"), M, "C19")
Case 3, 6, 9, 12
Call CopyAndTranspose(Range("DataZone"), M, "C32")
End Select
End With
closers1:
rs.Close
Set rs = Nothing
...
...
End Sub
Sub CopyAndTraspose(rngData As Range, month As Long, celltrg A
String)
'where rngData is the table copied from recordset
'month (I've three months on 4 sheets)
'celltrg is the first cell of the target range
'
On Error GoTo err_hnd
Application.ScreenUpdating = False
Application.Calculation = xlCalculationManual
rngData.Select
Selection.Copy
Select Case month
Case 1, 2, 3
Sheets("1Trim").Activate
Sheets("1trim").Select
Case 4, 5, 6
Sheets("2Trim").Activate
Sheets("2trim").Select
Case 7, 8, 9
Sheets("3Trim").Activate
Sheets("3trim").Select
Case 10, 11, 12
Sheets("4Trim").Activate
Sheets("4trim").Select
End Select
Range(celltrg).Select
Selection.PasteSpecial Paste:=xlPasteValues, Transpose:=True
Application.Calculation = xlCalculationAutomatic
Application.ScreenUpdating = True
Exit Sub
err_hnd:
MsgBox Err.Description & " " & Err.Number, vbOKOnly & " Su
CopyAndTraspose"
Resume Next
End Sub
Someone has a tip for me?
Emilian
end of the Excel session. The retrieving or saving data task from Acces
to Excel and viceversa, however, is very slow so I am trying to get
faster routine.
Currently, to retrieve the data, I read ADO recordsets and assign th
fields value to the target ranges. To save to Access, viceversa,
append/update validating the recordset fields with the cell values.
To retrieve (and similarly to save) the data, I have tested th
following routine: since the Access tables are transposed respect to th
ranges I need to populate, I import the table on a sheet by th
CopyFromRecordset method, select the data range, copy the selection an
PasteSpecial it transposed on the range I need. *Surprisingly the resul
I get is slower than that currently used!!*.
Here is the routine I use to Retrieve the Data form Access...
Sub RetrevingData(month as long)
'
' here other not interesting instructions
'
M = CLng(month)
ID = ID_filter
Year = Range("1Trim!AO1").Value
Set cn = New ADODB.Connection
With cn
.Provider = "Microsoft.jet.OLEDB.4.0"
.Properties("Data Source") = appath & "people.mdb"
.Properties("Jet OLEDBatabase Password") = PWORD
.Open
End With
Set rs = New ADODB.Recordset
'SQLstr = "SELECT tb1.*, Year([Data1]) AS Y, Month([Data1]) AS M
tb1.CID FROM tb1 WHERE " _
'& "(((Year([Data1]))=" & Year & ") AND ((Month([Data1]))=" & Mont
& " ) AND ((tb1.CID)=" & ID & "));"
SQLstr = "SELECT tb1.T, tb1.V, tb1.A, tb1.P, tb1.S, tb1.R " _
& "FROM tb1 WHERE (((Year([Data1]))=" & Year & ") AN
((Month([Data1]))=" & M & ") AND ((tb1.CID)=" & ID & "));"
With rs
.Open SQLstr, cn, 3, 3, adCmdText
Sheets("LoadData").Activate
Sheets("LoadData").Select
Range("DataZone").Select
Range("DataZone").Clear
Range("LoadData!A1").CopyFromRecordset rs
Select Case M
Case 1, 4, 7, 10
Call CopYAndTranspose(Range("DataZone"), M, "C6")
Case 2, 5, 8, 11
Call CopyAbdTranspose(Range("DataZone"), M, "C19")
Case 3, 6, 9, 12
Call CopyAndTranspose(Range("DataZone"), M, "C32")
End Select
End With
closers1:
rs.Close
Set rs = Nothing
...
...
End Sub
Sub CopyAndTraspose(rngData As Range, month As Long, celltrg A
String)
'where rngData is the table copied from recordset
'month (I've three months on 4 sheets)
'celltrg is the first cell of the target range
'
On Error GoTo err_hnd
Application.ScreenUpdating = False
Application.Calculation = xlCalculationManual
rngData.Select
Selection.Copy
Select Case month
Case 1, 2, 3
Sheets("1Trim").Activate
Sheets("1trim").Select
Case 4, 5, 6
Sheets("2Trim").Activate
Sheets("2trim").Select
Case 7, 8, 9
Sheets("3Trim").Activate
Sheets("3trim").Select
Case 10, 11, 12
Sheets("4Trim").Activate
Sheets("4trim").Select
End Select
Range(celltrg).Select
Selection.PasteSpecial Paste:=xlPasteValues, Transpose:=True
Application.Calculation = xlCalculationAutomatic
Application.ScreenUpdating = True
Exit Sub
err_hnd:
MsgBox Err.Description & " " & Err.Number, vbOKOnly & " Su
CopyAndTraspose"
Resume Next
End Sub
Someone has a tip for me?
Emilian