Querying a Database for Information with Variable ValuesLast reviewed: February 5, 1998Article ID: Q127127 |
The information in this article applies to:
SUMMARYYou can use WordBasic to query an MS Access database to retrieve information using variables as criteria. This article contains a macro that illustrates this procedure using DDE. WARNING: ANY USE BY YOU OF THE CODE PROVIDED IN THIS ARTICLE IS AT YOUR OWN RISK. Microsoft provides this macro code "as is" without warranty of any kind, either express or implied, including but not limited to the implied warranties of merchantability and/or fitness for a particular purpose. For best compatibility across with all Access versions, keep the quotations for the SQL statement in proper sequence. This should avoid any Word/Access, or DDE errors.
Sub MAIN CompName$ = "Eastern Connection" ContName$ = "Ann Devon" Connect$ = "TABLE Customers" DSN$ = "C:\MSOFFICE\ACCESS\SAMPAPPS\NWIND.MDB" SQL$ = "SELECT * FROM [Customers] WHERE (([Contact Name] = '" + ContName$+ "') AND ([Company Name] = '" + CompName$ + "'))" InsertDatabase .Connection = Connect$, .SQLStatement = SQL$, .DataSource =DSN$ End SubNote: In case it's difficult to distinguish single quotation marks from double quotation marks in the SQL$ = line above, the following line uses SQ for the single quotation mark and DQ for double quotation marks: SQL $ = DQSELECT * FROM [Customers] WHERE (([Contact Name] = SQDQ + ContName$ + DQSQ) AND ([Company Name] = SQDQ + CompName$ + DQSQ))DQ
|
KBCategory: kbmacro
© 1998 Microsoft Corporation. All rights reserved. Terms of Use. |