I am using SQL pass-through queries in MS Access 97 to run reports against Oracle databases. The user enters a date range in a form (and potentially other criteria) and clicks a button to preview a report. The button runs a macro that deletes the query and runs code that rebuilds the query using input from the form (dates, etc.). I have the following code working until I apply Access security.
The user will be using their default SYSTEM.MDW so they will be logged in as the user Admin. When I try to lock down permissions for Admin, I get error 3033 '...insufficient priviledges for MSYSTABLES...'
Currently Admin has all priviledges except Administer for all queries. Admin also has all priviledges for the system tables except Administer. I could not find a system object call 'MSYSTABLES'.
My goal is to use a pass-through query for performance reasons that can accept user input from a form. My other goal is to secure the database from users changing the query. The integrity of the query design is important to protect.
The code I currently have working:
Function WC_by_Week()
Dim db As Database
Dim qd As QueryDef
Dim ID As String
Dim IDCriteria As String
Dim FormID As String
Set db = CurrentDb()
'Check the Main form to see if Employee ID is "None", Null or an ID.
If IsNull(Forms("frm Main".Controls("EmployeeID".Value) Then
ID = "LABOR.EMPLOYEE_ID, "
IDCriteria = ""
Else
If Forms("frm Main".Controls("EmployeeID".Value = "None" Then
ID = ""
IDCriteria = ""
Else
If Len(Forms("frm Main".Controls("EmployeeID".Value) = 7 Then
ID = "LABOR.EMPLOYEE_ID, "
IDCriteria = "AND LABOR.EMPLOYEE_ID = '" & Forms![frm Main]![EmployeeID] & "' "
Else
MsgBox "You must enter a valid Employee ID"
End If
End If
End If
' Create a QueryDef object to retrieve
' data from Labor tables.
Set qd = db.CreateQueryDef("qry Work Center Weekly"
With qd
.Connect = "ODBC;DSN=whatif;DBQ=WHATif;"
.SQL = "SELECT SOPN.PO_WORK_CENTER_ID, " & _
ID & _
"NEXT_DAY(LABOR.DATE,'FRIDAY') AS WEEK_END, " & _
"SUM(LABOR.MFG_HOURS) AS MFG, " & _
"SUM(LABOR.ENG_HOURS) AS ENG, " & _
"SUM(DECODE(LUNCH_BREAK_VALUE,Null,HOURS_PROCESSED,0,HOURS_PROCESSED,HOURS_PROCESSED-LUNCH_BREAK_VALUE)) AS HOURS_WORKED, " & _
"LABOR.DEPT_CODE " & _
"FROM LABOROWNER.LABOR LABOR, " & _
"CSIOWNER.SOPN SOPN " & _
"WHERE (LABOR.RECORD_CODE='L' OR LABOR.RECORD_CODE = 'S') " & _
"AND (TO_NUMBER(SOPN.MAJOR_SEQ_NBR) = LABOR.MAJOR_SEQ_NBR) " & _
"AND LABOR.ORD_NBR = SOPN.ORD_NBR " & _
IDCriteria & _
"AND LABOR.DATE >= TO_DATE('" & Forms![frm Main]![BeginDate] & "','mm/dd/yyyy') " & _
"AND LABOR.DATE <= TO_DATE('" & Forms![frm Main]![EndDate] & "','mm/dd/yyyy') " & _
"GROUP BY LABOR.DEPT_CODE, " & _
"SOPN.PO_WORK_CENTER_ID, " & _
ID & _
"NEXT_DAY(LABOR.WORK_DATE,'FRIDAY'); "
End With
End Function
Thanks in advance...
The user will be using their default SYSTEM.MDW so they will be logged in as the user Admin. When I try to lock down permissions for Admin, I get error 3033 '...insufficient priviledges for MSYSTABLES...'
Currently Admin has all priviledges except Administer for all queries. Admin also has all priviledges for the system tables except Administer. I could not find a system object call 'MSYSTABLES'.
My goal is to use a pass-through query for performance reasons that can accept user input from a form. My other goal is to secure the database from users changing the query. The integrity of the query design is important to protect.
The code I currently have working:
Function WC_by_Week()
Dim db As Database
Dim qd As QueryDef
Dim ID As String
Dim IDCriteria As String
Dim FormID As String
Set db = CurrentDb()
'Check the Main form to see if Employee ID is "None", Null or an ID.
If IsNull(Forms("frm Main".Controls("EmployeeID".Value) Then
ID = "LABOR.EMPLOYEE_ID, "
IDCriteria = ""
Else
If Forms("frm Main".Controls("EmployeeID".Value = "None" Then
ID = ""
IDCriteria = ""
Else
If Len(Forms("frm Main".Controls("EmployeeID".Value) = 7 Then
ID = "LABOR.EMPLOYEE_ID, "
IDCriteria = "AND LABOR.EMPLOYEE_ID = '" & Forms![frm Main]![EmployeeID] & "' "
Else
MsgBox "You must enter a valid Employee ID"
End If
End If
End If
' Create a QueryDef object to retrieve
' data from Labor tables.
Set qd = db.CreateQueryDef("qry Work Center Weekly"
With qd
.Connect = "ODBC;DSN=whatif;DBQ=WHATif;"
.SQL = "SELECT SOPN.PO_WORK_CENTER_ID, " & _
ID & _
"NEXT_DAY(LABOR.DATE,'FRIDAY') AS WEEK_END, " & _
"SUM(LABOR.MFG_HOURS) AS MFG, " & _
"SUM(LABOR.ENG_HOURS) AS ENG, " & _
"SUM(DECODE(LUNCH_BREAK_VALUE,Null,HOURS_PROCESSED,0,HOURS_PROCESSED,HOURS_PROCESSED-LUNCH_BREAK_VALUE)) AS HOURS_WORKED, " & _
"LABOR.DEPT_CODE " & _
"FROM LABOROWNER.LABOR LABOR, " & _
"CSIOWNER.SOPN SOPN " & _
"WHERE (LABOR.RECORD_CODE='L' OR LABOR.RECORD_CODE = 'S') " & _
"AND (TO_NUMBER(SOPN.MAJOR_SEQ_NBR) = LABOR.MAJOR_SEQ_NBR) " & _
"AND LABOR.ORD_NBR = SOPN.ORD_NBR " & _
IDCriteria & _
"AND LABOR.DATE >= TO_DATE('" & Forms![frm Main]![BeginDate] & "','mm/dd/yyyy') " & _
"AND LABOR.DATE <= TO_DATE('" & Forms![frm Main]![EndDate] & "','mm/dd/yyyy') " & _
"GROUP BY LABOR.DEPT_CODE, " & _
"SOPN.PO_WORK_CENTER_ID, " & _
ID & _
"NEXT_DAY(LABOR.WORK_DATE,'FRIDAY'); "
End With
End Function
Thanks in advance...