Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

need to extract WHERE clause from access query in code 1

Status
Not open for further replies.

danielemc2

Programmer
Apr 23, 2002
4
US
I am creating a list of queries for the user to select from.

Dim obj As AccessObject
Dim dbs As Object
For Each obj In dbs.AllQueries
QueriesList.RowSource = QueriesList.RowSource + obj.Name + ";"
End If
Once they have chosen a query I need to get the sql from it.
These are SELECT queries and I need to build and run an UPDATE query based on the WHERE clause.

Is this possible?
 
You can declare an object as a querydef and get the SQL that way. The code would look like:

Sub GetSQLWhere()
Dim qry As DAO.QueryDef, str As String
Set qry = CurrentDb.QueryDefs("qryNRDTasks")

str = qry.SQL

str = Right(str, Len(str) - InStr(1, str, "WHERE") + 1)
If InStr(1, str, "ORDER BY") Then
str = Left(str, InStr(1, str, "ORDER BY") - 3)
End If

Set qry = Nothing

End Sub

This will give you the "WHERE" clause including the "WHERE" and without the "ORDER BY"
Kyle [pipe]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top