Parameters.Add method (Excel)

Creates a new query parameter.

Syntax

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 that the ODBC driver is expecting to receive. Microsoft Excel and the ODBC driver manager will coerce the parameter value given in Excel into the correct data type for the driver.

Return value

A Parameter object that represents the new query parameter.

Example

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

Support and feedback

Have questions or feedback about Office VBA or this documentation? Please see Office VBA support and feedback for guidance about the ways you can receive support and provide feedback.