April 2006
Beginner
1114 pages
98h 16m
English
parameters.Add(Name, [iDataType])
Creates a new query parameter. Returns a Parameter object.
|
Argument |
Description |
|---|---|
|
|
A string that identifies the parameter. |
|
|
If you want to specify a data type for the parameter, use one of the following constants: xlParamTypeBigInt xlParamTypeBinary xlParamTypeBit xlParamTypeChar xlParamTypeDate xlParamTypeDecimal xlParamTypeDouble xlParamTypeFloat xlParamTypeInteger xlParamTypeLongVarBinary xlParamTypeWChar xlParamTypeNumeric xlParamTypeLongVarChar xlParamTypeReal xlParamTypeSmallInt xlParamTypeTime xlParamTypeTimeStamp xlParamTypeTinyInt xlParamTypeUnknown xlParamTypeVarBinary xlParamTypeVarChar |
The following code creates a query table that uses a parameter to supply the product ID to the underlying query. The ? character is a placeholder for the query value, which in this case is the value 10 for the ProductID:
Dim strConn As String
Dim qt As QueryTable
Dim param As Parameter
strConn = "ODBC;DSN=MS Access Database;" & _
"DBQ=C:\Program Files\Microsoft Office\OFFICE11\SAMPLES\Northwind.mdb;"
Set qt = ActiveSheet.QueryTables.Add(Connection:=strConn, _
Destination:=ActiveSheet.Range("A1"))
qt.CommandText = "SELECT * FROM Products WHERE (Products.ProductID=?)"
Set param = qt.Parameters.Add("ProductsParam")
param.SetParam xlConstant, 10
qt.RefreshRead now
Unlock full access