Solved

Passing parameters to SQL - MS Access

Posted on 2000-03-17
3
226 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
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…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

734 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