Thread
:
Trying DROP TABLE in SQL from Excel
View Single Post
#
4
Posted to microsoft.public.excel.programming
Bernard Soh
external usenet poster
Posts: 3
Trying DROP TABLE in SQL from Excel
Thanks for all the replies. I have figured out the problem I was
facing with ADO which I tried unsuccessfully earlier.
Instead of doing a
Dim cnn as New ADODB.Connection
Dim cmd as New ADODB.Command
(which will give me a user-defined type not defined)
I did a
Dim cnn As Object
Dim cmd As Object
Set cnn = CreateObject("ADODB.Connection")
Set cmd = CreateObject("ADODB.Command")
cnn.ConnectionString = "DSN=mydsn;UID=myUID;PWD=myPWD"
cnn.Open
cmd.ActiveConnection = cnn
cmd.CommandText = "blah blah sql"
cmd.Execute
Thanks for the advises which helped me find the solution.
Regards.
Bernard.
(Bernard Soh) wrote in message . com...
Hi all
I am trying to do a DROP TABLE in MSSQL from Excel without success
(well, at least with partial success).
Enclosed is the code:
sSql = "if exists (select * from dbo.sysobjects where id =
object_id(N'tmpCst')) DROP TABLE tmpCst"
Selection.QueryTable.Sql = sSql
' for some reason the query will not run with
BackgroundQuery:=False
Selection.QueryTable.Refresh BackgroundQuery:=True
' loop added but never ends
Do While Selection.QueryTable.Refreshing
Sleep (1000)
Loop
What's happening is that if I run the code with BackgroundQuery:=True,
it executes perfectly, table is dropped. However this means that my
next lines of codes will start executing, and that won't do. So I add
a line to check while query is still Refreshing, if not sleep for
1sec, check again, but it never ends. It will work in debug mode,
meaning if I step thru the .Refreshing code it will actually complete.
I have checked that even at the point when it sleeps for the first
time, the SQL command is executed already (table is dropped) but the
.Refreshing remains True. Only if there is a break will the
.Refreshing change to a False.
Any help here is appreciated.
Regards.
Bernard.
Reply With Quote
Bernard Soh
View Public Profile
Find all posts by Bernard Soh