Information générale
Catégorie:
Bases de données DAO/RDO/ODBC/ADO
Noel,
Try this sample:
Dim objCon As ADODB.Connection
Dim objCmd As ADODB.Command
Dim objRst As ADODB.Recordset
Dim objPar As ADODB.Parameter
Dim ConnectionString as String
ConnectionString = "Your connecntion, user, password, etc."
Set objCon = New ADODB.Connection
Set objCmd = New ADODB.Command
objCon.Open ConnectionString
objCmd.ActiveConnection = objCon
objCmd.CommandText = "Your_Access_Query_Name"
objCmd.CommandType = adCmdStoredProc
Set objPar = objCmd.CreateParameter("query_parameter_Name", adChar, adParamInput, 12, "Parameter_value")
objCmd.Parameters.Append objPar
Set objRst = objCmd.Execute
Note the CreateParameter function has the following paremeter:
First parameter is the parameter name of your Query.
Second parameter is the constant which signify the type of your parameter.
Third parameter is the constant that signify the use of your parameter where it is for output, input. On this sample it will ask to input a value.
Fourth parameter is the width of your data type.
Fifth parameter is the value of your parameter.
Rene
Hi to all,
I have an MS-Access Query that accepts a date parameter. If the view is opened in MS-Access, it works fine. You can enter for the parameter.
But how do I pass the parameter from VB Code to retrieve the Query?
Here is my Code:
ObjCon.Open ConnectionString
SQL = "SELECT * FROM qrySALES"
Set RS = ObjCon.Execute(SQL)
... do something here...
RS.Close
ObjCon.Close
Set RS = Nothing
Set ObjCon = Nothing
Where:
qrySALES is a QUERY from MS-Access that accepts a date parameter.
I tried to place a WHERE clause in the SQL statement but it create a syntax error.
Thanks in Advance,
Noel
Précédent
Suivant
Répondre
Voir le fil de ce thread
Voir le fil de ce thread à partir de ce message seulement
Voir tous les messages de ce thread
Voir tous les messages de ce thread à partir de ce message seulement