View Single Post
  #4   Report Post  
Posted to microsoft.public.excel.programming
Damian Carrillo[_3_] Damian Carrillo[_3_] is offline
external usenet poster
 
Posts: 19
Default How to populate VBA Variables from ADODB.Connection Results?

Joel,

I'm unable to get your code to work. *There's two problems. *The
first, MySelect and MyWhere aren't declared values. I assumed them to
be strings, but then ran into the second problem: an ODBC SQL Server
Driver error "Incorrect syntax near the keyword Select. *I'm guessing
its because we're trying to send multiple selects in a single
statement without encapsulation. Or maybe because we're trying to send
vbCrLf in the statement but it needs to be a single string.

So instead I tried to adapt your code back to my original code,
changing only the line:

* * * *UserInfo(x) = RecSet
TO
* * * *Let UserInfo(x) = RecSet.Fields.Item(x).Value

This worked for the first field (EMPLOYEE_CODE) but the
RecSet.Fields.Item(x).Value failed after the first loop through the
FOR...NEXT statement.

-Damian


Okay I figured it out. I used my old code with your statement

Let UserInfo(x) = RecSet.Fields.Item(0).Value

Changing the Item(x) to Item(0) fixed the problem. So in the end your
effort helped me. Thanks Joel!

-Damian