 |
| 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
|
|
|
|

January 31st, 2005, 11:50 AM
|
|
Registered User
|
|
Join Date: Jan 2005
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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.
|
|

January 31st, 2005, 11:57 AM
|
|
Friend of Wrox
|
|
Join Date: Oct 2004
Posts: 564
Thanks: 0
Thanked 4 Times in 4 Posts
|
|
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
|
|

January 31st, 2005, 12:00 PM
|
|
Registered User
|
|
Join Date: Jan 2005
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
I need to be able to get at it using vba
|
|

January 31st, 2005, 12:04 PM
|
|
Registered User
|
|
Join Date: Jan 2005
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
I need to use the query thru vba
|
|

January 31st, 2005, 12:08 PM
|
|
Friend of Wrox
|
|
Join Date: Oct 2004
Posts: 564
Thanks: 0
Thanked 4 Times in 4 Posts
|
|
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
|
|

January 31st, 2005, 12:12 PM
|
|
Registered User
|
|
Join Date: Jan 2005
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
That is what I need to do!!!!
|
|

January 31st, 2005, 01:48 PM
|
|
Friend of Wrox
|
|
Join Date: Oct 2004
Posts: 564
Thanks: 0
Thanked 4 Times in 4 Posts
|
|
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
|
|

January 31st, 2005, 06:07 PM
|
|
Friend of Wrox
|
|
Join Date: Oct 2004
Posts: 564
Thanks: 0
Thanked 4 Times in 4 Posts
|
|
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
|
|

January 31st, 2005, 08:44 PM
|
|
Registered User
|
|
Join Date: Jan 2005
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Thanks,
I'll give it a try and let you know.
|
|

February 1st, 2005, 10:42 AM
|
|
Registered User
|
|
Join Date: Jan 2005
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Thanks,
It worked great!!! Just what I needed!!
|
|
 |