Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsFormsForms ProgrammingQueriesModules / DAO / VBAReports / PrintingMacrosDatabase DesignSecurityConversionImporting / LinkingSQL Server / ADPMultiuser / NetworkingReplicationSetup / ConfigurationDeveloper ToolkitsActiveX ControlsNew UsersGeneral 1General 2
Access DirectoryToolsTutorialsUser Groups
Related Topics
SQL ServerOther DB ProductsMS OfficeMore Topics ...

MS Access Forum / General 1 / February 2006

Tip: Looking for answers? Try searching our database.

Set Security on using VBA in saved Access Query

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
tomlebold@msn.com - 15 Feb 2006 04:38 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
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)
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.