How to use QueryTable with insertion sql

  • Thread starter Thread starter ou
  • Start date Start date
O

ou

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
 
ou said:
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.

--
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top