LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default SQL Query Destination as an array varable

Here is my macro:

Sub SQL2ARRAY()
connstring = "ODBC;DSN=DBSRV;UID=;PWD=;Database=BPC_Reports "
sqlstring = "SELECT * FROM BPC_Reports.dbo.Officers"
Set RS = CreateObject("ADODB.Recordset")
RS.Open "sqlstring", "connstring"
YourVar = RS.GetRows
Set RS = Nothing
MsgBox YourVar
End Sub

But I'm getting this error:

Run-time error '-2147467259 (80004005)':
Automation error
Unspecified error

I'm completely new to SQL queries and using them in excel macros...

What am I missing?



AA2e72E wrote:
I need my code for the SQL query to put the results into an array varable

(or something like that) that I can refrence.

Try:

Set RS = CreateObject("ADODB.Recordset")
RS.Open "Your SQL", "Your Connection String"
YourVar= RS.GetRows
Set RS = Nothing

At this point, YourVar is an array (2-dimensional).


 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to create a lookup table with an added varable? GIZZMO Excel Worksheet Functions 3 April 6th 09 10:32 PM
Error: Number of query values and destination fields are not the s Secret Squirrel Excel Worksheet Functions 0 December 3rd 05 02:26 AM
How can I assign a varable to equal an array? (it allready has a name) hamma_thrower Excel Programming 4 September 6th 05 03:09 PM
Query for data in an array anonymous Excel Programming 2 January 13th 04 12:51 PM
Range as varable Rod Taylor Excel Programming 2 July 28th 03 01:41 AM


All times are GMT +1. The time now is 08:15 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"