HOWTO: Work w/ Microsoft Access QueryDef Parameter Using VB 5.0Last reviewed: March 2, 1998Article ID: Q181782 |
The information in this article applies to:
SUMMARYThis article contains examples that illustrate how to call a Microsoft Access 97 parameterized QueryDef and return an ADO recordset using Visual Basic version 5.0. Examples are given for both text and numeric input parameters.
MORE INFORMATIONThe following examples illustrate ways to return an ADO recordset from a Microsoft Access QueryDef, which expects a parameter in order to return a recordset of one or more rows. The sample application contains three procedures that use Microsoft Access 97 QueryDefs that use parameters. The first procedure shows an example of passing a numeric parameter while the second procedure shows an example of passing a text parameter. The first two procedures show how to create an ADO parameter collection and define all the parameter properties to have an ADO recordset returned. The third procedure shows how to use the ADO Parameters.Refresh method to return the properties of a parameter. NOTE: You need to acquire and install the Microsoft Data Access Components (MDAC) version 1.5 stack for the sample in this article. The first requirement is to create the Microsoft Access 97 QueryDefs. This article assumes the reader is familiar with creating new QueryDefs in Microsoft Access 97. The following Visual Basic (VB) 5.0 code expects two new QueryDefs in the sample Nwind.mdb included with VB 5.0. Create the new QueryDefs with the following properties:
Query Name Table Criteria On Field Datatype ------------------------------------------------------------ ProductsByID Products [ProductID] ProductID Integer CustomerByID Customers [CustomerID] CustomerID TextMake sure you also set the parameter name and datatype in Microsoft Access 97 by selecting Query, and then click Parameters. After the Microsoft Access 97 QueryDef's are created, open a new Visual Basic 5.0 Project. Form1 is created by default. Under Project, References select Microsoft ActiveX Data Objects 1.5 Library. Follow these steps:
You may have noticed that another way to get a recordset back from a Microsoft Access QueryDef is to use the Parameter.Refresh method rather than defining the parameter properties in a parameter collection. This actually works although an extra round trip is necessary to the server. However, when passing a text parameter an error occurs because the correct size of a text parameter is not returned by invoking the Parameter.Refresh method. A size property is required when passing a text parameter. This property can be set before creating the ADO recordset to avoid the error.
REFERENCESFor additional information on MDAC 1.5, please see the following article in the Microsoft Knowledge Base:
ARTICLE-ID: Q175018 TITLE : HOWTO: Acquire and Install the Microsoft Oracle ODBC Driver v2.0 |
Additional query words: vbwin
© 1998 Microsoft Corporation. All rights reserved. Terms of Use. |