Parameters.Add Method (Excel)

Published: July 16, 2012

Creates a new query parameter.

expression .Add(Name, iDataType)

expression A variable that represents a Parameters object.

Parameters

Name

Required/Optional

Data Type

Description

Name

Required

String

The name of the specified parameter. The parameter name should match the parameter clause in the SQL statement.

iDataType

Optional

Variant

The data type of the parameter. Can be any XlParameterDataType constant. These values correspond to ODBC data types. They indicate the type of value the ODBC driver is expecting to receive. Microsoft Excel and the ODBC driver manager will coerce the parameter value given in Microsoft Excel into the correct data type for the driver.

Return Value

A Parameter object that represents the new query parameter.

This example changes the SQL statement for query table one. The clause "(city=?)" indicates that the query is a parameter query, and the value of city is set to the constant "Oakland."

Set qt = Sheets("sheet1").QueryTables(1) 
qt.Sql = "SELECT * FROM authors WHERE (city=?)" 
Set param1 = qt.Parameters.Add("City Parameter", _ 
 xlParamTypeVarChar) 
param1.SetParam xlConstant, "Oakland" 
qt.Refresh

Community Additions

ADD
Show:
© 2014 Microsoft