Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 146
  • Last Modified:

Passing an ado command to a function

How do I pass an ado delete command to a function?
0
JezzaKashel
Asked:
JezzaKashel
1 Solution
 
Alon_hCommented:
Hi JezzaKashel.

Like that :

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

0
 
VincentLawlorCommented:
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
 
JezzaKashelAuthor Commented:
These don't seem to work. I either get an invalid qualifer message, or type mismatch. A standard select command works perfectly
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
GrahamAtJobserveCommented:
Have you coded up your delete statement properly? Try cutting and pasting it into an access query or sqlserver query analyser
0
 
kahleanCommented:
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
 
DanRollinsCommented:
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
 
Computer101Commented:
Comment from expert accepted as answer

Computer101
E-E Moderator
0

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now