Wrox Programmer Forums
| Search | Today's Posts | Mark Forums Read
Access Discussion of Microsoft Access database design and programming. See also the forums for Access ASP and Access VBA.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Access section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
  #1 (permalink)  
Old January 31st, 2005, 11:50 AM
Registered User
 
Join Date: Jan 2005
Location: orland park, il, USA.
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Default Access queries

How do I get to the WHERE clause of a query that my user created.
I need to get to the source of a query (the text)to use in another query as they have entered it.


  #2 (permalink)  
Old January 31st, 2005, 11:57 AM
Friend of Wrox
 
Join Date: Oct 2004
Location: Clinton, UT, USA.
Posts: 564
Thanks: 0
Thanked 4 Times in 4 Posts
Default

If you go to the design view of a query and then choose SQL View under the View menu, you will be able to see the entire SQL statement. Alternatively, you can just look at the values entered in the criteria portion for each field.

Hope that helps

Mike

Mike
EchoVue.com
  #3 (permalink)  
Old January 31st, 2005, 12:00 PM
Registered User
 
Join Date: Jan 2005
Location: orland park, il, USA.
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I need to be able to get at it using vba

  #4 (permalink)  
Old January 31st, 2005, 12:04 PM
Registered User
 
Join Date: Jan 2005
Location: orland park, il, USA.
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I need to use the query thru vba

  #5 (permalink)  
Old January 31st, 2005, 12:08 PM
Friend of Wrox
 
Join Date: Oct 2004
Location: Clinton, UT, USA.
Posts: 564
Thanks: 0
Thanked 4 Times in 4 Posts
Default

Before I go off on a tangent (possibly) If I understand correctly, you have a database that has a query in it, and you want to be able to pull the WHERE clause out of the query from within a VBA module?

Mike
EchoVue.com
  #6 (permalink)  
Old January 31st, 2005, 12:12 PM
Registered User
 
Join Date: Jan 2005
Location: orland park, il, USA.
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Default

That is what I need to do!!!!

  #7 (permalink)  
Old January 31st, 2005, 01:48 PM
Friend of Wrox
 
Join Date: Oct 2004
Location: Clinton, UT, USA.
Posts: 564
Thanks: 0
Thanked 4 Times in 4 Posts
Default

Hi Kathy,

Well, it sounds easy enough, but as yet I haven't figured it out. I should have a few hours later today, so I will try then, and let you know. I am sure it will be one of those easy, kick yourself solutions!!

Mike

Mike
EchoVue.com
  #8 (permalink)  
Old January 31st, 2005, 06:07 PM
Friend of Wrox
 
Join Date: Oct 2004
Location: Clinton, UT, USA.
Posts: 564
Thanks: 0
Thanked 4 Times in 4 Posts
Default

This isn't very pretty, but it will do the job. I could probably tidy it up a little if you would like, but have a look at it and see if it makes sense, and let me know. This function pulls the WHERE Clause out of the qryTest query. You could pass that name in as a String.

Mike

Function TestSQL()

    Dim varQuery As QueryDef
    Dim varFoundQuery As Boolean
    Dim strSQL As String
    Dim whereClause As String
    Dim intLocation As Long

    varFoundQuery = False

    For Each varQuery In CurrentDb.QueryDefs
        If varQuery.Name = "qryTest" Then
            strSQL = varQuery.SQL
            varFoundQuery = True
            Exit For
        End If
    Next
    If varFoundQuery Then
        intLocation = InStr(1, strSQL, "WHERE")
        If intLocation > 1 Then
            whereClause = Right(strSQL, (Len(strSQL) - intLocation + 1))
            MsgBox whereClause
        End If
    End If

End Function

Mike
EchoVue.com
  #9 (permalink)  
Old January 31st, 2005, 08:44 PM
Registered User
 
Join Date: Jan 2005
Location: orland park, il, USA.
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks,
I'll give it a try and let you know.

  #10 (permalink)  
Old February 1st, 2005, 10:42 AM
Registered User
 
Join Date: Jan 2005
Location: orland park, il, USA.
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks,
It worked great!!! Just what I needed!!





Similar Threads
Thread Thread Starter Forum Replies Last Post
Help with delete queries on Access Morgz1 VS.NET 2002/2003 0 April 10th, 2006 10:45 AM
how to generate reports from access using queries nebujacob2000 Access VBA 3 November 18th, 2005 05:11 AM
MS Access Queries LDFProfessions Access 5 April 14th, 2005 07:35 AM
Access and Excel Queries in VB Mihai B Access VBA 1 January 24th, 2005 08:40 AM
Access queries and Crystal Report 9.0 Dmitriy Pro VB 6 1 March 11th, 2004 09:21 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.