Enable/Disable shift open key IF

823

Member
Local time
Today, 17:59
Joined
Jan 25, 2025
Messages
54
Hi,

I would need to have a code that lock shif key at startup both for FE and BE, but when file "unlock_shift.txt" will be present on c:\ the shift key will be enabled.
Someone can write this code?

thanks

I found this code below on this forum but it works in another way because if the file "unlock_shift.txt" is not present the db is locked "forever" :
Code:
Function sara_shift_open()

   Dim db As DAO.Database
   Dim prop As Property
   Const PropNotFound = 3270

   Set db = CurrentDb()
   On Error GoTo CatturaErrore

   db.Properties("AllowByPassKey") = False   'Disable shift key

   '  Using the file unlock_shift.txt as "password":
   '    if the file is present on the machine (@C:\),
   '    then the shift_open key is enable.
   '    Otherwise, it's disable (on my PC the file will be present,
   '    so I will be able to enable shift_open key so to access tables).

   If Dir("C:\unlock_shift.txt") <> "" Then
      db.Properties("AllowByPassKey") = True   'enable shift key
   End If

CatturaExit:
   On Error Resume Next
   Set db = Nothing
   Exit Function

CatturaErrore:
   If Err = PropNotFound Then
      Set prop = db.CreateProperty("AllowByPassKey", dbBoolean, True, True)
      db.Properties.Append prop
      Resume Next
   Else
      Resume CatturaExit
   End If

End Function
 
Quite simply the bypass is locked at the start.
If the file is not there then nothing changes?, what do you not understand about that :(

So that file HAS TO BE THERE to switch the bypass back to True. You then have to exit the db and reopen for that to take effect.
 
OK but I would need a code that
If file "unlock_shift.txt" is present on c:\ ---->Shiftkey enabled
If file "unlock_shift.txt" is not on c:\ ---->Shiftkey disabled
 
You already have that? :(
Run the code manually with the file present and see what it does.
 
If you want to start the application with shift key, you must remove AllowByPassKey before starting the application.

Another thought: Maybe you just want to prevent the usual application start. Then it would be sufficient not to execute it as soon as file unlock_shift.txt is available.
 
If someone can modify or re-write the code in this way:

If file "unlock_shift.txt" is present on c:\ ---->Shiftkey enabled
If file "unlock_shift.txt" is not on c:\ ---->Shiftkey disabled

Thanks
 
Hi. Did you see my post in your other thread? You may not need to worry about making this code work, if you can simply use the utility I mentioned.
 
  • Like
Reactions: 823
thanks theDBguy!

that tool doesn't works on my access because it is written only for 32bit (I have access 64bit)... I unable to modify it for 64bit... I don't know if you, or someone can fix it for 64bit ??
If it will run for access 64 bit, it is ok for me, thanks!



Nobody can post a code that do this:

If file "unlock_shift.txt" is present on c:\ ---->Shiftkey enabled
If file "unlock_shift.txt" is not on c:\ ---->Shiftkey disabled


thank you!
 
Last edited:
If someone can modify or re-write the code in this way:

If file "unlock_shift.txt" is present on c:\ ---->Shiftkey enabled
If file "unlock_shift.txt" is not on c:\ ---->Shiftkey disabled

Thanks
I was going to sugegst a simple If - Else - End If and an Application.Quit if being set to False.
 
thanks theDBguy!

that tool doesn't works on my access because it is written only for 32bit (I have access 64bit)... I unable to modify it for 64bit... I don't know if you, or someone can fix it for 64bit ??
If it will run for access 64 bit, it is ok for me, thanks!



Nobody can post a code that do this:

If file "unlock_shift.txt" is present on c:\ ---->Shiftkey enabled
If file "unlock_shift.txt" is not on c:\ ---->Shiftkey disabled


thank you!
 
Nobody can post a code that do this:
I would say: because it is not possible to implement this in one pass according to your example code.
AllowBypassKey requires a restart of the application to take effect.
=> Change AllowBypassKey from the outside or rebuild the start code so that the unwanted start procedures are not started with an existing file.

I remove the AllowByPass property with a VB script call via the file context menu.

RemoveAllowByPass.png

+
Code:
option explicit
Dim dbe, db, app
set app = CreateObject("Access.Application")
Set dbe = app.DBEngine
Set db = dbe.OpenDatabase(WScript.Arguments(0))
With db
On error resume next
  .Properties.Delete "AllowBypassKey"
  .Close
End With
set db = nothing
Set dbe = Nothing
 
Last edited:
  • Like
Reactions: 823
as said on the last post, you need a Startup db to run that code against the "target" db.
or you can use a vbscript as your startup file.
 
I have attempted to make that code that @theDBguy linked to, 64bit, but I am on 32bit.
It compiles for me, so try and compile it for you.
Thank you Gasman!
Now the file is ok also for 64bit! (only "browse" button doesn't open any folder....I have just to insert it manually...but this is not a big problem)
But It works only if the db is not splitted!
In my case I have splitted db (FE+BE) and I would like to remove the shiftkey at statup at both the DBs
 
I am not sure if it affects a BE, as no code should be in that?
 
I would say: because it is not possible to implement this in one pass according to your example code.
AllowBypassKey requires a restart of the application to take effect.
=> Change AllowBypassKey from the outside or rebuild the start code so that the unwanted start procedures are not started with an existing file.

I remove the AllowByPass property with a VB script call via the file context menu.

View attachment 118382
+
Code:
option explicit
Dim dbe, db, app
set app = CreateObject("Access.Application")
Set dbe = app.DBEngine
Set db = dbe.OpenDatabase(WScript.Arguments(0))
With db
On error resume next
  .Properties.Delete "AllowBypassKey"
  .Close
End With
set db = nothing
Set dbe = Nothing
Thanks Josef. I understand....We can forget about this code I've copied in this thread. I tought it was easy to mod it....but now I understand that It is difficult!
The only thing that I am able to do is "copy the code into the new module" so I'm unable to do any mod at the code.

I hope to find a solution to remove the shift at FE + BE
 
ahhh ok.... so disable shifkey at startap at BE is not possible?
only for FE?
I will leave the experts to confirm, but I am not sure of what it could bypass in a BE?
That would likely be password protected, if need be.
 
  • Like
Reactions: 823
Thank you Gasman!
Now the file is ok also for 64bit! (only "browse" button doesn't open any folder....I have just to insert it manually...but this is not a big problem)
But It works only if the db is not splitted!
In my case I have splitted db (FE+BE) and I would like to remove the shiftkey at statup at both the DBs
You did compile the code I hope?
 

Users who are viewing this thread

Back
Top Bottom