Article ID: 210242 - Last Review: June 23, 2005 - Revision: 4.0 How to implement Query by Form (QBF) with dynamic QueryDef in Access 2000This article was previously published under Q210242 Advanced: Requires expert coding, interoperability, and multiuser
skills. This article applies only to a Microsoft Access database (.mdb). For a Microsoft Access 97 version of this article,
see
136062
(http://support.microsoft.com/kb/136062/
)
. On This PageSUMMARY This article demonstrates how to use a form to specify the
criteria for a query that is dynamically built by a Visual Basic for
Applications function. This technique is called Query By Form (QBF). NOTE: You can see a demonstration of the technique that is used in this article in the sample file Qrysmp00.exe. For information about how to obtain this sample file, please see the following article in the Microsoft Knowledge Base: 207626
(http://support.microsoft.com/kb/207626/EN-US/
)
ACC2000: Access 2000 Sample Queries Available in Download Center
MORE INFORMATIONMicrosoft provides programming examples for illustration only, without warranty either expressed or implied. This includes, but is not limited to, the implied warranties of merchantability or fitness for a particular purpose. This article assumes that you are familiar with the programming language that is being demonstrated and with the tools that are used to create and to debug procedures. Microsoft support engineers can help explain the functionality of a particular procedure, but they will not modify these examples to provide added functionality or construct procedures to meet your specific requirements. NOTE: The sample code in this article uses Microsoft Data Access
Objects. For this code to run properly, you must reference the Microsoft DAO
3.6 Object Library. To do so, click References on the Tools menu in the Visual Basic Editor, and make sure that the Microsoft DAO 3.6 Object Library check box is selected. You can use the QBF method to specify the criteria for filtering an existing query, but this method can become complex when you add additional fields to the form. For example, one such complication arises when you do not type a value in one of the form's criteria fields. A more flexible QBF technique is to use a Visual Basic function to dynamically create the SQL statement for a query that is deleted and re-created each time the function runs. This method avoids using an empty criteria field as part of the query's WHERE condition. Creating the Sample Visual Basic FunctionConcatenating (joining) SQL statements in Visual Basic requires that you type cast fields with special characters to inform the Microsoft Jet database engine about what field data types you are using. The following type-casting characters are used in this article:
Field Type Type-Casting Character
------------------------------------------
Text Single quotation mark (')
Date Number sign (#)
Numeric None
NOTE: In the following sample statements, an underscore (_) at the end of a line is used as a line-continuation character. Remove the underscore from the end of the line when re-creating these statements.
REFERENCESFor more
information about the CreateQueryDef method, click Microsoft Visual Basic Help on the Help menu, type createquerydef method in the Office Assistant or the Answer Wizard, and then click Search to view the topic. For more information about SQL statements, click Microsoft Access Help on the Help menu, type view or modify the sql statement behind an existing query in the Office Assistant or the Answer Wizard, and then click Search to view the topics returned. For additional information about the QBF technique, click the article number below to view the article in the Microsoft Knowledge Base: 209645
(http://support.microsoft.com/kb/209645/EN-US/
)
ACC2000: How to Use the Query by Form (QBF) Technique
210242
(http://support.microsoft.com/kb/210242/EN-US/
)
ACC2000: Query by Form (QBF) Using Dynamic QueryDef
| Article Translations
|

Back to the top
