Hi,
Does anyone know how to force OpenDatabase to open as read only. I've tried setting the ReadOnly argument to true to no avail. The main curveball is that the security on the file only allows users "Read & Execute" priviledges, but even trying to use the ReadOnly argument results in an "Error 3051".
When the users have write priviledges, the function works perfectly, but when you take them away, back to "Error 3051". Giving them permenant write priviledges would fix this problem, but then obviously they would be able to edit the database themselves by just opening it, so this isn't really an option.
Here's the function exactly as I have it (You can ignore everything below the "FinishProcedure" label):
Does anyone know how to force OpenDatabase to open as read only. I've tried setting the ReadOnly argument to true to no avail. The main curveball is that the security on the file only allows users "Read & Execute" priviledges, but even trying to use the ReadOnly argument results in an "Error 3051".
When the users have write priviledges, the function works perfectly, but when you take them away, back to "Error 3051". Giving them permenant write priviledges would fix this problem, but then obviously they would be able to edit the database themselves by just opening it, so this isn't really an option.
Here's the function exactly as I have it (You can ignore everything below the "FinishProcedure" label):
Code:
Public Function FileIO_QueryDB(ByVal MDBFilePath As String, ByVal SQLQuery As String, Optional ByVal OpenReadOnly As Boolean = True) As Recordset
Dim MDBFile As Database
Dim MDBRecords As Recordset
Dim RecordIndex As Integer
Dim UserErrorDescription As String
Dim AdminErrorDescription As String
On Error GoTo ErrHandler
Set MDBFile = OpenDatabase(MDBFilePath, False, OpenReadOnly)
Set MDBRecords = MDBFile.OpenRecordset(SQLQuery)
Set FileIO_QueryDB = MDBRecords
Set MDBFile = Nothing
Set MDBRecords = Nothing
FinishProcedure:
Exit Function
ErrHandler:
Select Case Err.Number
Case 3051
UserErrorDescription = "You do not have access to a necessary database."
AdminErrorDescription = "User cannot access .mdb file: " & MDBFilePath
Call EmailsAndErrors_FlagError(Err.Number, 2, "FileIO_GetTotalTableRecords", UserErrorDescription, AdminErrorDescription, True)
Case Else
Call EmailsAndErrors_FlagError(Err.Number, -1, "FileIO_QueryDB", , , True)
End Select
End Function