Comparing data on two tabs
Thanks for the replies so far. Tom, I saw your post linking to ADO.
And this seems much more familiar to me(as i could use sql). One
problem I am encountering so far. I can not return a recordset
containing mulitple records?? here is my code so far
Private Sub getData(sourceFile As String, SourceRange As String,
TargetRange As Range, IncludeFieldNames As Boolean, TypeofClass As
String)
Dim TargetCell As Range
Dim i As Integer
dbConnectionString = "DRIVER={Microsoft Excel Driver (*.xls)};" &
"ReadOnly=1;DBQ=" & sourceFile
Set dbConnection = New ADODB.Connection
On Error GoTo InvalidConnection
dbConnection.Open dbConnectionString 'open the database
'Set rs = dbConnection.Execute("[" & SourceRange & "]")
Dim rstTables As ADODB.Recordset
Set rstTables = dbConnection.OpenSchema(adSchemaTables)
Set rs = New ADODB.Recordset
SQL = "Select * FROM " & SourceRange
rs.Open SQL, dbConnection
Set TargetCell = TargetRange.Cells(1, 1)
If IncludeFieldNames Then
For i = 0 To rs.Fields.Count - 1
TargetCell.Offset(0, i).Formula = rs.Fields(i).Name
Next i
Set TargetCell = TargetCell.Offset(1, 0)
End If
If TypeofClass = "Prosight" Then
While Not rs.EOF
TargetCell.Offset(0, 0).Formula = rs.Fields(1).Value
TargetCell.Offset(0, 1).Formula = rs.Fields(10).Value
TargetCell.Offset(0, 2).Formula = rs.Fields(0).Value
TargetCell.Offset(0, 3).Formula = rs.Fields(31).Value
rs.NextRecordset
Wend
End If
'TargetCell.CopyFromRecordset rs
Exit Sub
InvalidConnection:
MsgBox Err.Description, vbExclamation, "Incorrect Data"
End Sub
The Err.Description = "Current Provider does not support returning
mulitple recordsets from a single execution"
|