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

x
?
Solved

Passing parameters to SQL - MS Access

Posted on 2000-03-17
3
Medium Priority
?
229 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 150 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

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Question has a verified solution.

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

Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
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…
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…
Suggested Courses

885 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