Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Microsoft Office > Access and Access VBA > Access
Password Reminder
Register
| FAQ | Members List | Calendar | 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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #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.


Reply With Quote
  #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
Reply With Quote
  #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

Reply With Quote
  #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

Reply With Quote
  #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
Reply With Quote
  #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!!!!

Reply With Quote
  #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
Reply With Quote
  #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
Reply With Quote
  #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.

Reply With Quote
  #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!!

Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


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



All times are GMT -4. The time now is 01:14 PM.


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