Solved

Passing an ado command to a function

Posted on 2001-07-26
7
137 Views
Last Modified: 2013-11-23
How do I pass an ado delete command to a function?
0
Comment
Question by:JezzaKashel
7 Comments
 

Expert Comment

by:Alon_h
ID: 6321186
Hi JezzaKashel.

Like that :

Function Func(tmp As ADODB.Recordset)
   ...
End Function

0
 
LVL 4

Expert Comment

by:VincentLawlor
ID: 6321202
Dim cmd as ADODB.Command

cmd.CommandText = "DELETE * FROM X WHERE Y = Z"

Sub DoSomethingWithCommand(cmd as ADODB.Command)

    cmd.ActiveConnection = connection
    cmd.Execute

End Sub

Vin.
0
 

Author Comment

by:JezzaKashel
ID: 6321247
These don't seem to work. I either get an invalid qualifer message, or type mismatch. A standard select command works perfectly
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

Expert Comment

by:GrahamAtJobserve
ID: 6321346
Have you coded up your delete statement properly? Try cutting and pasting it into an access query or sqlserver query analyser
0
 
LVL 6

Accepted Solution

by:
kahlean earned 100 total points
ID: 6321391
I would suggest that you pass your delete sql query as string instead of a ado command. This prove to be much easier.


To call this function

DeleteRecordset <dsn name>, <SQL query>

Example

Dim SQL As String

SQL = DELETE * FROM A"

DeletRecordset bibliodsn, SQL

********************************************************************

Public Sub DeleteRecordset(ByVal ConnectionString As String, ByVal Source As String)

On Error GoTo ErrorHandler

    objConnection.CursorLocation = adUseClient
    objConnection.Open ConnectionString, "sa", ""

    Set objCommand = New ADODB.Command
    objCommand.CommandType = adCmdText
    objCommand.CommandText = Source
    Set objCommand.ActiveConnection = objConnection
   
    objCommand.Execute (Source)
   
    Set objCommand = Nothing
    objConnection.Close
   
End Sub

***********************************************************
0
 
LVL 49

Expert Comment

by:DanRollins
ID: 7161556
Hi JezzaKashel,
It appears that you have forgotten this question. I will ask Community Support to close it unless you finalize it within 7 days. I will ask a Community Support Moderator to:

    Accept kahlean's comment(s) as an answer.

JezzaKashel, if you think your question was not answered at all or if you need help, just post a new comment here; Community Support will help you.  DO NOT accept this comment as an answer.

EXPERTS: If you disagree with that recommendation, please post an explanatory comment.
==========
DanRollins -- EE database cleanup volunteer
0
 
LVL 1

Expert Comment

by:Computer101
ID: 7182421
Comment from expert accepted as answer

Computer101
E-E Moderator
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Performance of SQL statement 37 101
how can i search if string exist in array ? 3 50
clicking a shape in a frame array vb6 3 40
Advice in Xamarin 21 57
Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

864 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

24 Experts available now in Live!

Get 1:1 Help Now