Lock Program

G

George

How can I lock my program so that anyone that knows Access
can't get inside my database by holding down the shift key
while the program opens.

Thanks
 
M

Mike M.T.

To create a true lock for your application:

1. Create a new form with 2 command buttons and add the following code:

Private Sub Command0_Click()

'************** Alter default settings ******************

Dim db As DAO.Database
Dim pty1 As Property
Dim pty2 As Property
Dim pty3 As Property
Dim pty4 As Property
Dim pty5 As Property
Dim pty6 As Property
Dim pty7 As Property
Dim pty8 As Property
Dim pty9 As Property

On Error GoTo NoShift_Err
Set db = CurrentDb

'*********** Make shure the user isn't bothered ***************
Application.SetOption "Confirm Record Changes", False
Application.SetOption "Confirm Document Deletions", False
Application.SetOption "Confirm Action Queries", False

'******* Disable some features not needed at runtime **********
db.Properties("StartupShowDBWindow").Value = False
db.Properties("AllowFullMenus").Value = False
db.Properties("AllowBreakIntoCode").Value = False
db.Properties("AllowSpecialKeys").Value = False
db.Properties("AllowBypassKey").Value = False
db.Properties("AllowBuiltinToolbars").Value = False

'*********** Set some customized properties ***************
db.Properties("StartupForm").Value = "frmSplash"
db.Properties("AppTitle").Value = "PutAppTitleHere"
db.Properties("AppIcon").Value = "IconFullPathHere"

NoShift_Exit:
Exit Sub
NoShift_Err:
If Err.Number = 3270 Then
Set pty1 = db.CreateProperty("StartupShowDBWindow", dbBoolean, False)
Set pty2 = db.CreateProperty("AllowFullMenus", dbBoolean, False)
Set pty3 = db.CreateProperty("AllowBreakIntoCode", dbBoolean, False)
Set pty4 = db.CreateProperty("AllowSpecialKeys", dbBoolean, False)
Set pty5 = db.CreateProperty("AllowBypassKey", dbBoolean, False)
Set pty6 = db.CreateProperty("AllowBuiltinToolbars", dbBoolean, False)
Set pty7 = db.CreateProperty("StartupForm", dbText, "frmSplash")
Set pty8 = db.CreateProperty("AppTitle", dbText, "PutAppTitleHere")
Set pty9 = db.CreateProperty("AppIcon", dbText, "IconFullPathHere")

db.Properties.Append pty1
db.Properties.Append pty2
db.Properties.Append pty3
db.Properties.Append pty4
db.Properties.Append pty5
db.Properties.Append pty6
db.Properties.Append pty7
db.Properties.Append pty8
db.Properties.Append pty9
Else
MsgBox Err.Description
Resume NoShift_Exit
End If
End Sub

Private Sub Command1_Click()

'************** Restore default settings *****************

Dim db As DAO.Database
Dim pty1 As Property
Dim pty2 As Property
Dim pty3 As Property
Dim pty4 As Property
Dim pty5 As Property
Dim pty6 As Property
Dim pty7 As Property
Dim pty8 As Property
Dim pty9 As Property
On Error GoTo AllowShift_Err

Set db = CurrentDb

Application.SetOption "Confirm Record Changes", True
Application.SetOption "Confirm Document Deletions", True
Application.SetOption "Confirm Action Queries", True

db.Properties("StartupShowDBWindow").Value = True
db.Properties("AllowFullMenus").Value = True
db.Properties("AllowBreakIntoCode").Value = True
db.Properties("AllowSpecialKeys").Value = True
db.Properties("AllowBypassKey").Value = True
db.Properties("AllowBuiltinToolbars").Value = True
db.Properties("StartupForm").Value = "(none)"
db.Properties("AppTitle").Value = "PutAppTitleHere"
db.Properties("AppIcon").Value = "IconFullPathHere"

AllowShift_Exit:
Exit Sub

AllowShift_Err:
If Err.Number = 3270 Then
Set pty1 = db.CreateProperty("StartupShowDBWindow", dbBoolean, True)
Set pty2 = db.CreateProperty("AllowFullMeDas", dbBoolean, True)
Set pty3 = db.CreateProperty("AllowBreakIntoCode", dbBoolean, True)
Set pty4 = db.CreateProperty("AllowSpecialKeys", dbBoolean, True)
Set pty5 = db.CreateProperty("AllowBypassKey", dbBoolean, True)
Set pty6 = db.CreateProperty("AllowBuiltinToolbars", dbBoolean, True)
Set pty7 = db.CreateProperty("StartupForm", dbText, "(none)")
Set pty8 = db.CreateProperty("AppTitle", dbText, "PutAppTitleHere")
Set pty9 = db.CreateProperty("AppIcon", dbText, "IconFullPathHere")
db.Properties.Append pty1
db.Properties.Append pty2
db.Properties.Append pty3
db.Properties.Append pty4
db.Properties.Append pty5
db.Properties.Append pty6
db.Properties.Append pty7
db.Properties.Append pty8
db.Properties.Append pty9
Else
MsgBox Err.Description
Resume AllowShift_Exit
End If
End Sub

2. You can open this form from your application and enable (runtime mode)
or disable (debug mode) the custom settings by clicking the buttons.

3. Exit and reopen database for effect.
 
V

Van T. Dinh

But anyone who knows how to enabled the AllowBypassKey by code will be able
to enable it and then use the Shift Key ...

You need to implement Access Security (and it is still not 100% secure
either).

--
HTH
Van T. Dinh
MVP (Access)
 
J

Joseph Meehan

I suggest you start by reading
http://support.microsoft.com/default.aspx?scid=kb;[LN];207793

Access security is a great feature, but it is, by nature a complex product
with a very steep learning curve. Properly used it offers very safe
versatile protection and control. However a simple mistake can lock
everyone including God out.

Practice on some copies to make sure you know what you are doing.
 
G

George

Thanks for all the responses but I simply need is a way to
keep the novice person out not a professional hacker..
 
M

Mike M.T.

This is intended to keep the inexperienced users away from the database
layout.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top