Connect to SQL2005 DB from excel VBA

Get help on databases - MySQL, Oracle, Access, etc.
Post Reply
DeeVeeDee
Registered User
Posts: 172
Joined: 09 Apr 2010, 15:18

Connect to SQL2005 DB from excel VBA

Post by DeeVeeDee »

Ive got the following code which works.

Code: Select all

MyQuery = "INSERT INTO FC_VALUES (ITEM_NUMBER,ITEM_DESC) VALUES ('EXCELTESTNUMBER','TEST DESCRIPTION')"
'MsgBox MyQuery

Sheets("Sheet1").Select
Range("A1").Select
Sqlstring = MyQuery '"select IDCUST from ARCUS"

connstring = "ODBC;DSN=ODBCTEST;UID=sa;PWD=password01#;Database=FC_DB"
With ActiveSheet.QueryTables.Add(Connection:=connstring, Destination:=Range("A1"), Sql:=Sqlstring)

 .Refresh
 End With
Problem is the above puts some text in to A1 which i dont want.
If i had to run the query twice its shifts A1 to A2 and put some text into A1 "Excel Query" or something like that.
I want to run a SQL query without it putting text on the sheet.

How can i do that?
I even tried to put the code in Sheet1 then Say Sheet2.A1
_̴ı̴̴̡̡̡ ̡͌l̡̡̡ ̡͌l̡*̡̡ ̴̡ı̴̴̡ ̡̡͡|̲̲̲͡͡͡ ̲▫̲͡ ̲̲̲͡͡π̲̲͡͡ ̲̲͡▫̲̲͡͡ ̲|̡̡̡ ̡ ̴̡ı̴̡̡ ̡͌l̡̡̡
Post Reply