DAO OpenDatabase failure

SumGuy

New Member
Joined
Jan 29, 2011
Messages
6
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):

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
 

Excel Facts

Add Bullets to Range
Select range. Press Ctrl+1. On Number tab, choose Custom. Type Alt+7 then space then @ sign (using 7 on numeric keypad)
My apologies, there was a small error in the code calling this function from when I was testing various routes. The error code is actually 3050.

Also, in case there are multiple differenct versions, the reference is "Microsoft DAO 3.6 Object Library" in Excel 2003.

If anyone can help it will be greatly appreciated.

Thanks in advance
 
Upvote 0

Forum statistics

Threads
1,223,231
Messages
6,170,885
Members
452,364
Latest member
springate

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top