Link to home
Start Free TrialLog in
Avatar of Kongta
KongtaFlag for Switzerland

asked on

SQL-Execute out of Access

I do have following code that doesn't work

Private Sub Form_Close()
Dim c As ADODB.Connection
Dim cmd As ADODB.Command
Dim Srv As Variant
Dim db As Variant
Dim rs As New Recordset

'Server_Info-------------------------------------------------
                    Srv = "7920"
                    db = "K"
'------------------------------------------------------------
Set c = New ADODB.Connection
c.ConnectionString = "Driver={SQL Server};Server=" & Srv & ";Database=" & db & ""
c.Open

c.Execute "DELETE FROM tblStatistikTmp_sb_Land"  
c.Execute "DELETE FROM tblStatistikTmp_sb_Index"
c.Execute "DELETE FROM tblStatistikTmp_sb_Sektor"
c.Execute "DELETE FROM tblStatistikChartTmp"        
c.Execute "DELETE FROM tblStatistikChartTmp_Spot"
c.Close

Set c = Nothing
End Sub

Connecting to the Server works on other issues when I execute a stored procedure and if I run the delete code on the SQL-Server directly, it works as well, no idea why it doesnt work out of the Access?
thx for any help
SOLUTION
Avatar of mbizup
mbizup
Flag of Kazakhstan image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
<That's what you should be executing, not the connection.>

That's typically what I use as well, but connection.execute is a valid approach (it should work unless there is something else going wrong).
Avatar of Norie
Norie

Agreed, I posted that incorrectly using Execute with a connection should work.

I just thought using the Command object might help in finding the problem.

Also it was there, so why not use it.:)

Avatar of Kongta

ASKER

I do have Microsoft ActiveX Data Objects 6. activated already.

Using mbizup's code, I get an error on cmd.Text  ?!
Kongta,

You're getting us confused.  I haven't suggested any code yet :)

Again - what was the exact issue (or error message) you were getting with the code you originally posted?
Avatar of Kongta

ASKER

Sorry, I just implemented my code in a blank form an ran it and it worked. Seems not to work in my other form which has a few graphs in it and three subforms, no idea why.
The code *should* fly syntactically.

Do any of the delete queries work (how about a delete query on a table that is unrelated to the form or subforms)?  Try them one at a time.

What are the recordsources of the form and subforms?
And what is the exact error message, if any?
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
You're not stupid - that happens to everyone.  :)

A point split (or a deletion) is fine with me, but if you want to award points, you should click the "Accept and Award Points" button under your own last comment.  That marks your answer as 'accepted' so that people reading this know what the resolution was, and it lets you award some or all of the points at your own discretion to different comments as 'assisted'
Avatar of Kongta

ASKER

thx, yeah, full in the code and didn't think about activation. rgds and nice weekend.