Locking a database?

afs24

Board Regular
Joined
Sep 26, 2002
Messages
237
How do I lock a database so that no one can get into design view or make changes?
 

Excel Facts

Create a chart in one keystroke
Select the data and press Alt+F1 to insert a default chart. You can change the default chart to any chart type
If you just want to stop unauthorised people using the database, you can set a password.
You can do the same for your code -- noone will be able to change any code anywhere in the project without the password.

BUT... if you really want to stop certain people getting into design view...

It's not simple. You need to implement some sort of security scheme (Access has a Security Wizard) which allows you to assign permissions to different groups -- Admin, Manager, User, for example.You then put people into the various groups and, as they log in, they get the permissions for the highest group to which they belong.
You can set permissions for adding / deleting / browsing records, viewing specific forms and reports, and more.

Don't just jump into it -- check Microsoft's site and it might be a good idea to check some of the Microsoft MVP sites -- http://www.mvps.org
 
Upvote 0
Another option is to create a MDE file. This will prevent viewing, modifying, or creating forms, reports, or modules in Design view, but will still allow the creation of tables/queries.
MDE files have all of their code saved in a compiled state so are a smaller file and in theory faster.

It all depends on who you are locking out and why :)
 
Upvote 0
So why is Access' built-in security so much better than Excel?

You'd think they'd make the same/similar arrangements between programs. (Understanding that entirely different development teams work on them though, I can see why not...)

Smitty
 
Upvote 0
So why is Access' built-in security so much better than Excel?
Because the guys who built Access are control freaks... :LOL:
Seriously, most if not all databases have security options built in that I haven't seen in spreadsheets. Possibly because databases are intended to be multiuser, whereas spreadsheets are mostly meant to be single-user environments.
Anyone else got 2 cents to throw in here?
 
Upvote 0
Not as to "Why" but a couple of points, The database password is fairly weak and if you do not encrypt the DB then in theory data could be grabed with a hex reader.
A DB secured with userlevel security and encrypted is for most puposes unbreakable.
Excel Worksheet protection can be broken with just two or three lines of code!

Peter
 
Upvote 0
No kidding...

I have a Workbook_Open enabled "Password Breaker" file for users who lock themselves out. (And distribute it frequently!)
 
Upvote 0
Here you go:
Code:
Public Sub AllInternalPasswords()
'Breaks worksheet and workbook structure passwords.
'Bob McCormick probably originator of base code algorithm
'Modified for coverage of workbook structure / windows
'passwords and for multiple passwords
'Norman Harker and JE McGimpsey 27-Dec-2002
'Reveals passwords NOT "the" passwords
Const DBLSPACE As String = vbNewLine & vbNewLine
Dim Mess As String, Header As String
Dim Authors As String, Version As String
Dim RepBack As String, AllClear As String
Dim PWord1 As String
Dim ShTag As Boolean, WinTag As Boolean
Dim w1 As Worksheet, w2 As Worksheet
Dim i As Integer, j As Integer, k As Integer, l As Integer
Dim m As Integer, n As Integer, i1 As Integer, i2 As Integer
Dim i3 As Integer, i4 As Integer, i5 As Integer, i6 As Integer
Application.ScreenUpdating = False
Header = "AllInternalPasswords        User Message"
Authors = DBLSPACE & vbNewLine & "Adapted from Bob " & _
          "McCormick base code by Norman Harker " & _
          "and JE McGimpsey"
Version = DBLSPACE & "Version 1.1 27-Dec-2002"
RepBack = DBLSPACE & "Please report success or " & _
          "failure back to newsgroup."
AllClear = DBLSPACE & "The workbook should now " & _
          "be free of all password protection so " & _
          "make sure you:" & DBLSPACE & _
          "SAVE IT NOW!" & DBLSPACE & _
          "and also" & DBLSPACE & _
          "BACKUP!, BACKUP!!, BACKUP!!!" & DBLSPACE & _
          "Also, remember that the password " & _
          "was put there for a reason. Don't " & _
          "stuff up crucial formulas or data." & _
          DBLSPACE & "Access and use of some data may" & _
          "be an offence. If in doubt, don't."
With ActiveWorkbook
    WinTag = .ProtectStructure Or .ProtectWindows
End With
ShTag = False
For Each w1 In Worksheets
        ShTag = ShTag Or w1.ProtectContents
Next w1
If Not ShTag And Not WinTag Then
    Mess = "There were no passwords on sheets, or workbook " & _
                "structure or windows." & Authors & Version
    MsgBox Mess, vbInformation, Header
    Exit Sub
End If
Mess = "After pressing OK button this will take some time." & _
        DBLSPACE & "Amount of time depends on how " & _
        "many different passwords, the passwords, and" & _
        "your computer's specification." & DBLSPACE & _
        "Just be patient! Make me a coffee!" & _
        Authors & Version
MsgBox Mess, vbInformation, Header
If Not WinTag Then
    Mess = "There was no protection to workbook structure " & _
           "or windows." & DBLSPACE & _
           "Proceeding to unprotect sheets." & _
           Authors & Version
    MsgBox Mess, vbInformation, Header
Else
  On Error Resume Next
  Do      'dummy do loop
    For i = 65 To 66: For j = 65 To 66: For k = 65 To 66
    For l = 65 To 66: For m = 65 To 66: For i1 = 65 To 66
    For i2 = 65 To 66: For i3 = 65 To 66: For i4 = 65 To 66
    For i5 = 65 To 66: For i6 = 65 To 66: For n = 32 To 126
    With ActiveWorkbook
      .Unprotect Chr(i) & Chr(j) & Chr(k) & _
         Chr(l) & Chr(m) & Chr(i1) & Chr(i2) & _
         Chr(i3) & Chr(i4) & Chr(i5) & Chr(i6) & Chr(n)
      If .ProtectStructure = False And _
      .ProtectWindows = False Then
          PWord1 = Chr(i) & Chr(j) & Chr(k) & Chr(l) & _
            Chr(m) & Chr(i1) & Chr(i2) & Chr(i3) & _
            Chr(i4) & Chr(i5) & Chr(i6) & Chr(n)
          Mess = "You had a Worksheet Structure or " & _
                 "Windows Password set." & DBLSPACE & _
                 "The password found was: " & DBLSPACE & _
                 PWord1 & DBLSPACE & "Note it down for " & _
                 "potential future use in other " & _
                 "workbooks by same person who set this " & _
                 "password." & DBLSPACE & _
                 "Now to check and clear other passwords." & _
                 Authors & Version
          MsgBox Mess, vbInformation, Header
          Exit Do  'Bypass all for...nexts
      End If
    End With
    Next: Next: Next: Next: Next: Next
    Next: Next: Next: Next: Next: Next
  Loop Until True
  On Error GoTo 0
End If
If WinTag And Not ShTag Then
  Mess = "Only structure / windows protected with " & _
         "the password that was just found." & _
         AllClear & Authors & Version & RepBack
  MsgBox Mess, vbInformation, Header
  Exit Sub
End If
On Error Resume Next
For Each w1 In Worksheets
  'Attempt clearance with PWord1
  w1.Unprotect PWord1
Next w1
On Error GoTo 0
ShTag = False
For Each w1 In Worksheets
  'Checks for all clear ShTag triggered to 1 if not.
  ShTag = ShTag Or w1.ProtectContents
Next w1
If Not ShTag Then
  Mess = AllClear & Authors & Version & RepBack
  MsgBox Mess, vbInformation, Header
  Exit Sub
End If
For Each w1 In Worksheets
  With w1
    If .ProtectContents Then
      On Error Resume Next
      Do      'Dummy do loop
        For i = 65 To 66: For j = 65 To 66: For k = 65 To 66
        For l = 65 To 66: For m = 65 To 66: For i1 = 65 To 66
        For i2 = 65 To 66: For i3 = 65 To 66: For i4 = 65 To 66
        For i5 = 65 To 66: For i6 = 65 To 66: For n = 32 To 126
        .Unprotect Chr(i) & Chr(j) & Chr(k) & _
          Chr(l) & Chr(m) & Chr(i1) & Chr(i2) & Chr(i3) & _
          Chr(i4) & Chr(i5) & Chr(i6) & Chr(n)
        If Not .ProtectContents Then
          PWord1 = Chr(i) & Chr(j) & Chr(k) & Chr(l) & _
            Chr(m) & Chr(i1) & Chr(i2) & Chr(i3) & _
            Chr(i4) & Chr(i5) & Chr(i6) & Chr(n)
          Mess = "You had a Worksheet password set." & _
                 DBLSPACE & "The password found was: " & _
                 DBLSPACE & PWord1 & DBLSPACE & _
                 "Note it down for potential future use " & _
                 "in other workbooks by same person who " & _
                 "set this password." & DBLSPACE & _
                 "Now to check and clear other passwords." & _
                 Authors & Version
          MsgBox Mess, vbInformation, Header
          'leverage finding Pword by trying on other sheets
          For Each w2 In Worksheets
            w2.Unprotect PWord1
          Next w2
          Exit Do  'Bypass all for...nexts
        End If
        Next: Next: Next: Next: Next: Next
        Next: Next: Next: Next: Next: Next
      Loop Until True
      On Error GoTo 0
    End If
  End With
Next w1
Mess = AllClear & Authors & Version & RepBack
MsgBox Mess, vbInformation, Header
End Sub
Hope that helps,

Smitty
 
Upvote 0
SydneyGeek said:
So why is Access' built-in security so much better than Excel?
Because the guys who built Access are control freaks... :LOL:
Seriously, most if not all databases have security options built in that I haven't seen in spreadsheets. Possibly because databases are intended to be multiuser, whereas spreadsheets are mostly meant to be single-user environments.
Anyone else got 2 cents to throw in here?

I just don't think spreadsheets are designed to be secure. A database application is normally designed so that certain users can update data, others can modify the design and others can read-only i.e. as SydneyGeek as mentioned; a multi-user environment where each individual has different requirements dependant on their role. From this perspective Access security HAS to be secure otherwise it would be not be a usable product. It would only be useful for breaking down data that is too big for Excel. I don't think the same applies to spreadsheets and this is why MS haven't implemented the same level of security in Excel. I'm actually of the opinion that Excel's security is more than adequate - stop users from overwriting formulas and from deleting worksheets from my nice workbook - nothing more needed :)
 
Upvote 0

Forum statistics

Threads
1,221,575
Messages
6,160,603
Members
451,657
Latest member
Ang24

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