Solved

Passing an ado command to a function

Posted on 2001-07-26
7
136 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
Comment Utility
Hi JezzaKashel.

Like that :

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

0
 
LVL 4

Expert Comment

by:VincentLawlor
Comment Utility
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
Comment Utility
These don't seem to work. I either get an invalid qualifer message, or type mismatch. A standard select command works perfectly
0
Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

 

Expert Comment

by:GrahamAtJobserve
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
Comment from expert accepted as answer

Computer101
E-E Moderator
0

Featured Post

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
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…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…

772 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

10 Experts available now in Live!

Get 1:1 Help Now