Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Microsoft Office > Access and Access VBA > Access
| Search | Today's Posts | Mark Forums Read
Access Discussion of Microsoft Access database design and programming. See also the forums for Access ASP and Access VBA.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Access section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
  #1 (permalink)  
Old February 14th, 2005, 11:59 AM
ru1 ru1 is offline
Authorized User
 
Join Date: Feb 2005
Location: Detroit, MI, USA.
Posts: 39
Thanks: 0
Thanked 0 Times in 0 Posts
Default Disable the [SHIFT Key] on Startup

Hi everyone. I would like to disable the [SHIFT] key on startup. Any ideas?

RU1
  #2 (permalink)  
Old February 14th, 2005, 10:00 PM
Friend of Wrox
 
Join Date: Jun 2003
Location: , , USA.
Posts: 1,093
Thanks: 1
Thanked 12 Times in 11 Posts
Default

Do you want to just flat out disalbe the SHIFT key, or do you want to disable user's ability to use the shift key as a means of bypassing your startup properties and the AutoExec macro?

Assuming you want to the latter, commonly implemented, functionality, you would simply toggle the AllowByPass property. The sub below sets AllowByPass to False, preventing user's from bypassing your startup properties. Set a reference to DAO and call the sub with:

SetByPassKey "AllowBypassKey", dbBoolean, False

(use True to enable the bypass)

Public Sub SetByPassKey(strPropName As String, _
   varPropType As Variant, _
   varPropValue As Variant)

   On Error GoTo Err_SetProperties

   Dim db As DAO.Database
   Dim prp As DAO.Property

   Set db = CurrentDb
   db.Properties(strPropName) = varPropValue
   Set db = Nothing

Exit_SetProperties:
   Exit Sub

Err_SetProperties:
   If Err = 3270 Then 'Property not found
       Set prp = db.CreateProperty( _
           strPropName, varPropType, varPropValue)
       db.Properties.Append prp
       Resume Next
   Else
       SetProperties = False
       MsgBox "SetProperties", Err.Number, Err.Description
       Resume Exit_SetProperties
   End If
End Sub

Once you've disabled the bypass key, a convenient way to enable it for administrative purposes is via a password. You can create a form (preferably accessible only by system admins), and place the following in the form module:

Private Sub cmdSetAllowBypassKey_Click()
   On Error GoTo Err_cmdSetAllowBypassKey_Click

   Dim strInput As String
   Dim strMsg As String

   Beep

   strMsg = "Do you want to enable the Bypass Key?" & vbCrLf & vbLf & _
   "Please key password to enable the Bypass Key."

   strInput = InputBox(Prompt:=strMsg, Title:="Disable Bypass Key Password")
   If strInput = "TypeYourBypassPasswordHere" Then
       SetProperties "AllowBypassKey", dbBoolean, True
       Beep
       MsgBox "The Bypass Key has been enabled." & vbCrLf & vbLf & _
       "The Shift key will allow the users to bypass the startup options " & _
       "the next time the database is opened.", _
       vbInformation, "Set Startup Properties"
   Else
       Beep
       SetProperties "AllowBypassKey", dbBoolean, False
       MsgBox "Incorrect ''AllowBypassKey'' Password!" & vbCrLf & vbLf & _
       "The Bypass Key was disabled." & vbCrLf & vbLf & _
       "The Shift key will NOT allow the users to bypass the startup options " & _
       "the next time the database is opened.", _
       vbCritical, "Invalid Password"
       Exit Sub
   End If
Exit_cmdSetAllowBypassKey_Click:
   Exit Sub
Err_cmdSetAllowBypassKey_Click:
   MsgBox "cmdSetAllowBypassKey_Click", Err.Number, Err.Description
   Resume Exit_cmdSetAllowBypassKey_Click
End Sub


Public Function SetProperties(strPropName As String, _
   varPropType As Variant, _
   varPropValue As Variant) As Integer

   On Error GoTo Err_SetProperties

   Dim db As DAO.Database
   Dim prp As DAO.Property

   Set db = CurrentDb
   db.Properties(strPropName) = varPropValue
   SetProperties = True
   Set db = Nothing

Exit_SetProperties:
   Exit Function

Err_SetProperties:
   If Err = 3270 Then 'Property not found
       Set prp = db.CreateProperty( _
           strPropName, varPropType, varPropValue)
       db.Properties.Append prp
       Resume Next
   Else
       SetProperties = False
       MsgBox "SetProperties", Err.Number, Err.Description
       Resume Exit_SetProperties
   End If
End Function

HTH,

Bob



  #3 (permalink)  
Old February 15th, 2005, 09:15 AM
ru1 ru1 is offline
Authorized User
 
Join Date: Feb 2005
Location: Detroit, MI, USA.
Posts: 39
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Quote:
quote:Originally posted by Bob Bedell
 Do you want to just flat out disalbe the SHIFT key, or do you want to disable user's ability to use the shift key as a means of bypassing your startup properties and the AutoExec macro?

Assuming you want to the latter, commonly implemented, functionality, you would simply toggle the AllowByPass property. The sub below sets AllowByPass to False, preventing user's from bypassing your startup properties. Set a reference to DAO and call the sub with:

SetByPassKey "AllowBypassKey", dbBoolean, False

(use True to enable the bypass)

Public Sub SetByPassKey(strPropName As String, _
varPropType As Variant, _
varPropValue As Variant)

On Error GoTo Err_SetProperties

Dim db As DAO.Database
Dim prp As DAO.Property

Set db = CurrentDb
db.Properties(strPropName) = varPropValue
Set db = Nothing

Exit_SetProperties:
Exit Sub

Err_SetProperties:
If Err = 3270 Then 'Property not found
     Set prp = db.CreateProperty( _
         strPropName, varPropType, varPropValue)
     db.Properties.Append prp
     Resume Next
Else
     SetProperties = False
     MsgBox "SetProperties", Err.Number, Err.Description
     Resume Exit_SetProperties
End If
End Sub

Once you've disabled the bypass key, a convenient way to enable it for administrative purposes is via a password. You can create a form (preferably accessible only by system admins), and place the following in the form module:

Private Sub cmdSetAllowBypassKey_Click()
On Error GoTo Err_cmdSetAllowBypassKey_Click

Dim strInput As String
Dim strMsg As String

Beep

strMsg = "Do you want to enable the Bypass Key?" & vbCrLf & vbLf & _
"Please key password to enable the Bypass Key."

strInput = InputBox(Prompt:=strMsg, Title:="Disable Bypass Key Password")
If strInput = "TypeYourBypassPasswordHere" Then
     SetProperties "AllowBypassKey", dbBoolean, True
     Beep
     MsgBox "The Bypass Key has been enabled." & vbCrLf & vbLf & _
     "The Shift key will allow the users to bypass the startup options " & _
     "the next time the database is opened.", _
     vbInformation, "Set Startup Properties"
Else
     Beep
     SetProperties "AllowBypassKey", dbBoolean, False
     MsgBox "Incorrect ''AllowBypassKey'' Password!" & vbCrLf & vbLf & _
     "The Bypass Key was disabled." & vbCrLf & vbLf & _
     "The Shift key will NOT allow the users to bypass the startup options " & _
     "the next time the database is opened.", _
     vbCritical, "Invalid Password"
     Exit Sub
End If
Exit_cmdSetAllowBypassKey_Click:
Exit Sub
Err_cmdSetAllowBypassKey_Click:
MsgBox "cmdSetAllowBypassKey_Click", Err.Number, Err.Description
Resume Exit_cmdSetAllowBypassKey_Click
End Sub


Public Function SetProperties(strPropName As String, _
varPropType As Variant, _
varPropValue As Variant) As Integer

On Error GoTo Err_SetProperties

Dim db As DAO.Database
Dim prp As DAO.Property

Set db = CurrentDb
db.Properties(strPropName) = varPropValue
SetProperties = True
Set db = Nothing

Exit_SetProperties:
Exit Function

Err_SetProperties:
If Err = 3270 Then 'Property not found
     Set prp = db.CreateProperty( _
         strPropName, varPropType, varPropValue)
     db.Properties.Append prp
     Resume Next
Else
     SetProperties = False
     MsgBox "SetProperties", Err.Number, Err.Description
     Resume Exit_SetProperties
End If
End Function

HTH,

Bob



  #4 (permalink)  
Old September 16th, 2007, 11:21 AM
Authorized User
 
Join Date: May 2004
Location: , , .
Posts: 12
Thanks: 0
Thanked 0 Times in 0 Posts
Default

When Excution gets to Set db = CurrentDb, it gives me msg
object Required

pls help me ?

  #5 (permalink)  
Old September 22nd, 2007, 09:27 PM
Friend of Wrox
 
Join Date: Jun 2003
Location: , , USA.
Posts: 1,093
Thanks: 1
Thanked 12 Times in 11 Posts
Default

You need to set a reference to the DAO object library.



Similar Threads
Thread Thread Starter Forum Replies Last Post
Help: Disable the "Shift Key" on macro Auto run ofAlexander Word VBA 1 June 24th, 2007 03:16 AM
Disable F10 key in IE chrscote Javascript 1 March 21st, 2006 07:23 AM
Shift + Enter OR Shift+Double-Click phungleon Access 2 May 20th, 2004 10:14 AM
Enable Shift Key to By Pass Macro! sampow Access 1 December 4th, 2003 07:46 PM
Trapping the Shift key yossarian Beginning VB 6 2 July 7th, 2003 08:03 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.