ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   How to use QueryTable with insertion sql (https://www.excelbanter.com/excel-programming/307198-how-use-querytable-insertion-sql.html)

ou

How to use QueryTable with insertion sql
 
Hi
I want to execute "insert into xxx" in the excel, but found that
everytime I need to specify a Range although the sql statement won't return
any data back. I really don't want to display anything inside excel when the
insertion is executed. So that's basically what I want and did:
I wrote a small GUI form inside the VB Editor of Excel. When the
user click some button on the form I will do an insertion. The following is
my code:

'oQts is the QueryTables collection of ActiveSheet
'lstConns let the user choose a connection string
'Range is where the data should go and my problem because I
don't want the data to appear on the excel
'sql is the insertion statement
Set oQt = oQts.Add(oQts.Item(lstConns.ListIndex + 1).connection,
Range("a1"), sql)
oQt.name = "MyTempTable"
'Execute the insertion
oQt.Refresh

Ok, that's what I tried to remove the "a1", I added after the code:
oQt.CancelRefresh
oQt.Delete
And the QueryTable is removed from the QueryTables but in the cell a1 I
still read "MyTempTable"

Is there anyway so that it won't appear on the excel? I tried to put the
Range("a1") as Range("") but the marco execution will fail



Jamie Collins

How to use QueryTable with insertion sql
 
"ou" wrote in message

I want to execute "insert into xxx" in the excel
everytime I need to specify a Range


You must specify the literal Range values in sql text e.g.

INSERT INTO MyTable (MyIntCol, MyTextCol) VALUES (1, 'One')

Jamie.

--


All times are GMT +1. The time now is 01:41 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com