All,
Not really an Access question, BUT thought someone may have an idea as it's related to querying other data sources.
I'm trying to return data using the ODBCDirect method from an Oracle Database,
So far I have:
Private Sub ODBCDirectTest()
Dim wrkEG As Workspace
Dim cnnEG As Connection
Dim qdfEG As QueryDef
Dim Results As Recordset
Dim Ret As Boolean
Dim Record
Dim iCols As Integer
Set wrkEG = CreateWorkspace("myEG", "admin", "", dbUseODBC)
Set cnnEG = wrkEG.OpenConnection("", dbDriverNoPrompt, False, "ODBC;dsn=EG;uid=EGuser;pwd=EGpassword;")
Ret = wrkEG.Connections.Count
If Ret = False Then
MsgBox ("There was an Error connecting to the database"), vbCritical, "Error"
End
End If
Set qdfEG = cnnEG.CreateQueryDef("EGtemp")
qdfEG.Sql = "select * from EGselect"
qdfEG.CacheSize = 500
Set Results = qdfEG.OpenRecordset.GetRows
Worksheets("Data").Activate
Worksheets("Data").Range("A1").CurrentRegion.Clear
For iCols = 0 To Results.Fields.Count - 1
Worksheets("Data").Cells(1, iCols + 1).Value = Results.Fields(iCols).Name
Next
----------------------------------------
Dim x
x = Results.RecordCount
MsgBox x
cnnEG.Close
wrkEG.Close
End Sub
Up to the line the code inserts the field headings from the Database.
When in gets to:
x = Results.RecordCount
MsgBox x
the msgbox result is -1, Not the expected 5000 (the amount of records in the original table.)
I have used Results.RecordCount before using ODBC and Jet but not ODBCdirect, anyone have any idea how to pass the records back to the worksheet (i.e. place them into an array and return them to "A2:?? (?? = Cells(Results.Fields.Count, Results.RecordCount - 1)), or to another table (i.e. Access).
Sorry it's a bit vague (I haven't really got a clue what I'm on about at the minute), any further information needed just ask. Or any directions someone could nudge me in.
Thanks,
Not really an Access question, BUT thought someone may have an idea as it's related to querying other data sources.
I'm trying to return data using the ODBCDirect method from an Oracle Database,
So far I have:
Private Sub ODBCDirectTest()
Dim wrkEG As Workspace
Dim cnnEG As Connection
Dim qdfEG As QueryDef
Dim Results As Recordset
Dim Ret As Boolean
Dim Record
Dim iCols As Integer
Set wrkEG = CreateWorkspace("myEG", "admin", "", dbUseODBC)
Set cnnEG = wrkEG.OpenConnection("", dbDriverNoPrompt, False, "ODBC;dsn=EG;uid=EGuser;pwd=EGpassword;")
Ret = wrkEG.Connections.Count
If Ret = False Then
MsgBox ("There was an Error connecting to the database"), vbCritical, "Error"
End
End If
Set qdfEG = cnnEG.CreateQueryDef("EGtemp")
qdfEG.Sql = "select * from EGselect"
qdfEG.CacheSize = 500
Set Results = qdfEG.OpenRecordset.GetRows
Worksheets("Data").Activate
Worksheets("Data").Range("A1").CurrentRegion.Clear
For iCols = 0 To Results.Fields.Count - 1
Worksheets("Data").Cells(1, iCols + 1).Value = Results.Fields(iCols).Name
Next
----------------------------------------
Dim x
x = Results.RecordCount
MsgBox x
cnnEG.Close
wrkEG.Close
End Sub
Up to the line the code inserts the field headings from the Database.
When in gets to:
x = Results.RecordCount
MsgBox x
the msgbox result is -1, Not the expected 5000 (the amount of records in the original table.)
I have used Results.RecordCount before using ODBC and Jet but not ODBCdirect, anyone have any idea how to pass the records back to the worksheet (i.e. place them into an array and return them to "A2:?? (?? = Cells(Results.Fields.Count, Results.RecordCount - 1)), or to another table (i.e. Access).
Sorry it's a bit vague (I haven't really got a clue what I'm on about at the minute), any further information needed just ask. Or any directions someone could nudge me in.
Thanks,