Solved

Passing parameters to SQL - MS Access

Posted on 2000-03-17
3
224 Views
Last Modified: 2010-05-18
Here is my code :

Dim cmdPubs As ADODB.Command
Set cmdPubs = New ADODB.Command
Set cmdPubs.ActiveConnection = DtEnviromentFly.FlyConnection

  With cmdPubs
        .CommandType = adCmdStoredProc
        .CommandText = "{Call SQL_Acesso (?)}"
        .Parameters(0).Value = Popup.cmbName.Text
        .Parameters(0).Direction = adParamInput
        .Execute
End With

The code is returning a invalid SQL statement errror, when it executes .Parameters(0)..........

Did I forget something ? How could I pass parameters to a SQL in MS Access ?
0
Comment
Question by:mvianna
  • 2
3 Comments
 
LVL 2

Expert Comment

by:Tchalkov
ID: 2628591
Try this:
    cmdpubs.CommandText = "select * from ParamQry"
    Dim par As New ADODB.Parameter
    Set par = cmdpubs.CreateParameter("param", adInteger)
    cmdpubs.Parameters.Append par
    par.Value = Popup.cmbName.Text
       
   
   Set rs = cmdpubs.Execute
0
 
LVL 1

Accepted Solution

by:
advapp earned 50 total points
ID: 2628648
There is a document in the ADO help that covers this.  There are two ways to get there:

While in VB's IDE, and in the "With" clause of your code, enter:

  .Parameter.Append

and then place your cursor over Append and press F1.  This should bring up the ADO help file on the "Append Method" page.  Click on the "example" link and you should be taken to the "Append and CreateParameter Methods Example".

If that doesn't work, open C:\<OS>\Ado210.chm and look in:

Microsoft ActiveX Data Objects (ADO)
  Microsoft ADO Programmer's Reference
    Learning ADO | ADO Code Examples
      ADO Method Examples

This "book" contains the "Append and CreateParameter Methods Example" document.

This page explains how to handle parameters and avoid this error.

Good luck!
0
 
LVL 1

Expert Comment

by:advapp
ID: 2628652
Oh, I should've clarified that "<OS>" in the file path represents either "Windows" or "WinNT" depending on your system.  Plus, the path should have been:

"C:\<OS>\Help\Ado210.chm"

Sorry for the confusion.
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

838 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