The function or code below creates a saved query used as the record
source for forms and reports. The funtions is called each time a user
clicks on a button to display a form or report.
This works just after security has been set for the user by cheching
all options, which include
delete, modify, append and administer. Security is being set on the
tables, queries and forms.
The second time the user clicks on the button that runs the function
the security check boxes become unchecked. The problems seems to be
that the security needs to be checked just before the code creates the
saved query: Set qryCriteria = db.CreateQueryDef("qryCriteriaSelected",
SQL). How do set security in VBA code for query on object.
Dim SQL As String
Dim db As DAO.database
Dim qryCriteria As DAO.QueryDef
Dim ClearEndDate As String
On Error GoTo BuildSql_Err
'Select and From clause
SQL = "SELECT [Tbl-ContractInformation].*, WHERE "
'Build Reference Number Clause
If Not IsNull(Forms![frmSelectCriteria]![cboReferenceNumb]) Then
SQL = SQL & "([Tbl-ContractInformation].[ReferenceNumb] = "
SQL = SQL & "Forms![frmSelectCriteria]![cboReferenceNumb]) And
"
End If
'Build Reference Number Prefix Clause
If Not IsNull(Forms![frmSelectCriteria]![cboReferencePrefixNumb])
Then
SQL = SQL & "(Left([ReferenceNumb],5) = "
SQL = SQL &
"Forms![frmSelectCriteria]![cboReferencePrefixNumb]) And "
End If
SQL = SQL & " -1 = -1; "
Set db = DBEngine.Workspaces(0).Databases(0)
'Deletes the stored query def: qryCriteriaSelected
DoCmd.DeleteObject acQuery, "qryCriteriaSelected"
'Turn off Access system warning to create, delete or updates tables
DoCmd.SetWarnings False
'Create stored query def with return value deal criteria
Set qryCriteria = db.CreateQueryDef("qryCriteriaSelected", SQL)
Br@dley - 15 Feb 2006 06:12 GMT
> The function or code below creates a saved query used as the record
> source for forms and reports. The funtions is called each time a user
[quoted text clipped - 47 lines]
> 'Create stored query def with return value deal criteria
> Set qryCriteria = db.CreateQueryDef("qryCriteriaSelected", SQL)
The second time you run it the query is created again, therefore any
security settings will be lost.??

Signature
regards,
Br@dley
david epsom dot com dot au - 15 Feb 2006 07:17 GMT
Don't do it that way. Do this instead:
Set qryCriteria = db.QueryDefs("qryCriteriaSelected")
qryCriteria.SQL = SQL
(david)
> The function or code below creates a saved query used as the record
> source for forms and reports. The funtions is called each time a user
[quoted text clipped - 46 lines]
> 'Create stored query def with return value deal criteria
> Set qryCriteria = db.CreateQueryDef("qryCriteriaSelected", SQL)