VBA LOOP in ORACLE SQL -



VBA LOOP in ORACLE SQL -

i trying write vba run query assigned mysql when hcr_dm.hcr_dm_fact table loaded. i'm using count of distinct source in table decide if loaded.

when running macro below, got error message while line, saying object doesn't back upwards property or method.

i'm quite new vba, , couldn't figure out need adjusted. can 1 help me this?

thanks!

class="lang-vb prettyprint-override">const cnstr = "provider = oraoledb.oracle; info source =csdpro; odbc;driver={oracle odbc driver};server=csdpro;user id=hcr_sandbox;password=******" sub fillwithsqldata(strsql string, wksht string) ' given sql query , worksheet, fills worksheet info dump of sql query results ' define variables dim cn adodb.connection dim rs adodb.recordset dim sql_count string ' set variables set cn = new adodb.connection set rs = new adodb.recordset ' connect sql server cn .connectionstring = cnstr .open end ' query sql server , homecoming results info dump in cell a2 of specified worksheet rs .activeconnection = cn sql_count = "select count( distinct a.src_table) hcr_dm.hcr_dm_fact a" set rf = cn.execute(sql_count) while rf.fields.value = 8 .open strsql loop worksheets(wksht).range("a2").copyfromrecordset rs .close end ' close connection cn.close set rs = nil set conn = nil end sub sub refresh() ' define sql query dim mysql string mysql = "select a.oracle_fin_company_id || ' - ' || a.oracle_fin_company_desc company " & _ "from hcr_dm.legal_entity_summary " & _ "where a.company_header = 'filed'" ' take worksheet results should displayed dim mywksht string mywksht = "sheet1" ' phone call connection sub phone call fillwithsqldata(mysql, mywksht) end sub

you're not selecting field. lines

set rf = cn.execute(sql_count) while rf.fields.value = 8

should be

set rs = cn.execute(sql_count) while rs.fields(0).value = 8

also, note typo in declared rs you're filling rf recordset. recommend utilize option explicit statement help find these. can read more here.

sql oracle vba loops

Comments

Popular posts from this blog

formatting - SAS SQL Datepart function returning odd values -

c++ - Apple Mach-O Linker Error(Duplicate Symbols For Architecture armv7) -

php - Yii 2: Unable to find a class into the extension 'yii2-admin' -