UtterAccess HomeUtterAccess Wiki

Welcome Guest ( Log In | Register )

Custom Search
Edit Discussion
> MakeTestQuery    


Use this procedure to test sql strings you are using to create queries in VBA Code. You can optionally open the resulting query to view the results (or learn that it has an error) or switch to the Access development interface to view the query design and/or sql statement in the query's design view. Before using this code for the first time, create a simple query in design view and save it as "qTest" or any other name of your choice. If you use a different name, change the TestQuery constant definition.

When you are developing your code to build an sql string, call this procedure with your sql string as its argument.

' MakeTestQuery
' http://www.utteraccess.com/wiki/MakeTestQuery
' Code courtesy of UtterAccess Wiki
' Licensed under Creative Commons License
' http://creativecommons.org/licenses/by-sa/3.0/
' You are free to use this code in any application,
' provided this notice is left unchanged.
' rev  date                          brief descripton
' 1.0  2013-10-03                    
' MakeTestQuery
Public Sub MakeTestQuery(StrSQL As String)
' Procedure: MakeTestQuery
' Description: create a query from code for testing in query creator interface

   Const cstrProcedure = "MakeTestQuery"
   Const TestQuery = "qTest"

   Dim qdef As DAO.QueryDef

10  On Error GoTo HandleError

20  Set qdef = CurrentDb.QueryDefs(TestQuery)

30  qdef.SQL = StrSQL

40    If MsgBox("View Query Result?", vbYesNo, "TestQuery") = vbYes Then
50        DoCmd.OpenQuery (TestQuery)
60    End If


70  Exit Sub

'insert error handler here
End Sub

Creative Commons License
MakeTestQuery by UtterAccess Wiki is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.
Editing and revision of the content is freely encouraged; for details, see Expected Usage.

Edit Discussion
Custom Search

Thank you for your support!
This page has been accessed 6,119 times.  This page was last modified 15:17, 3 October 2013 by Glenn Lloyd.   Disclaimers