vba - Switching from ODBC to OLEDB and getting "Object Required" -


i have been tasked modifying vba code switch using odbc connection using oledb connection can code username , password subroutine.

i'm not experienced think i'm managed proper connection string new oledb connection.

i've tested connection string in standalone test sub , worked fine.

i'm attempting replace previous odbc connection strings in code i'm starting "run-time error '424' object required"

here sub trying work:

sub getdata() dim tablename string dim tablerecords new adodb.recordset dim cnxn2 adodb.connection   tablename = "table_name"  set cnxn2 = new adodb.connection  'old connection string using odbc 'cnxn2.connectionstring = "data source='datasource';" '& "integrated security = sspi;"  'new connection string using oledb cnxn2.connectionstring = "provider=sqloledb;data source=server\instance;user id=user;password=password;"  cnxn2.connectiontimeout = 30 cnxn2.open tablerecords.open tablename, cnxn2, aduseclient, adlockoptimistic, adcmdtable  tablerecords returndata.range("a1").copyfromrecordset tablerecords(10)  .close end         cnxn2.close          set cnxn2 = nothing         set tablerecords = nothing     end sub 

the error highlighting line stating "returndata.range("a1").copyfromrecordset tablerecords(1)

why getting object required errors when changed connection string?

note: there similar sub in code in location , deleted "returndata." mentioned line , seemed start working. if here though this: run-time error '430': class not support automation or not support expected interface

any why switching oledb breaking sub appreciated.

from code returndata not being created or anything, unless declaring global variable else where. imagine doing in excel. in case replace returndata.range("a1").copyfromrecordset tablerecords(10) like

activeworkbook.sheets("sheet1").range("a1").copyfromrecordset tablerecords(10) 

edit. managed replicate , fixed it. try this.

replace returndata.range("a1").copyfromrecordset tablerecords(10) like

activeworkbook.sheets("sheet1").range("a1").copyfromrecordset tablerecords 

Comments

Popular posts from this blog

php - failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request -

java - How to filter a backspace keyboard input -

java - Show Soft Keyboard when EditText Appears -