Discussion Locked

Access- how to change a group of queries

0 helpful
2 replies
Closed to new repliesThis discussion is closed. It stays readable, but it takes no new replies.

Can anyone show me the code needed to loop through all of the queries in a database and change the RunPermissions property to the "Owner's" value?

This is Access97, by the way.

Thanks!

2 replies

by esadacca

This will get you the list of queries... I've haven't yet found the property for "RunPermissions"

Public Sub ListQueries()
Dim db As Database, qdf As QueryDef

Set db = CurrentDb

For Each qdf In db.QueryDefs Debug.Print qdf.Name
Next qdf

Set db = Nothing
End Sub

by esadacca

Here's a "hack":

Public Sub UpdateQueries()
Dim db As Database, qdf As QueryDef, strSQL As String

Set db = CurrentDb

For Each qdf In db.QueryDefs
strSQL = Trim(UCase(qdf.SQL))

If InStr(1, strSQL, "WITH OWNERACCESSOPTION") = 0 Then
'remove the trailing semicolon
strSQL = Left(strSQL, InStr(1, strSQL, ";") - 1)
'append the "owneraccess" sql
strSQL = strSQL & " WITH OWNERACCESS OPTION;"
End If

qdf.SQL = strSQL
Next qdf

Set db = Nothing
End Sub

This discussion is closed to new replies.