I found a snippet of code that will pull data from oracle and populate cells supposedly... however I cannot get it to work here is the code
I have a sheet that is already formatted in the way of the report I need, so I am just trying to fill in the columns. There are multiple rows in the query so i just need to pick a spot and fill down til EOF. Any Ideas?
I have got it to work with one cell, just not a column so I know I am connecting to DB.
Code:
'Defining variables
Dim cnOra As ADODB.Connection
Dim rsOra As ADODB.Recordset
Dim db_name As String
Dim UserName As String
Dim Password As String
Set cnOra = New ADODB.Connection
Set rsOra = New ADODB.Recordset
db_name = "DB"
UserName = "myname"
Password = "mypw"
'Making an ODBC connection according to ADO
cnOra.Open "DSN=" + db_name + ";UID=" + UserName + ";PWD=" _
& Password + ";"
rsOra.CursorLocation = adUseServer
'Running a query
rsOra.Open "select * from works.registered", cnOra, adOpenForwardOnly
'Passing on data from the recordset to a variable or cell.
'Notice that the column name or alias is used to address
'data in the recordset.
While Not rsOra.EOF
Worksheets("Sheet1").Range("B1").End(xlDown).Offset(1, 0) _
= rsOra![REGISTERED]
rsOra.MoveNext
Wend
'Forgetting to close your connection will sometimes result in
'Dr.Watsons
rsOra.Close
cnOra.Close
Set rsOra = Nothing
I have a sheet that is already formatted in the way of the report I need, so I am just trying to fill in the columns. There are multiple rows in the query so i just need to pick a spot and fill down til EOF. Any Ideas?
I have got it to work with one cell, just not a column so I know I am connecting to DB.