Locking VBA project with code (1 Viewer)

KitaYama

Well-known member
Local time
Today, 11:47
Joined
Jan 6, 2022
Messages
1,552
The title says it all.

Is it possible to lock/unlock VBA project of a accdb file with code (vba)?

Thanks.
 

theDBguy

I’m here to help
Staff member
Local time
Yesterday, 19:47
Joined
Oct 29, 2018
Messages
21,485
Just off the top of my head (can't do any testing right now), but probably possible from an external app.
 

KitaYama

Well-known member
Local time
Today, 11:47
Joined
Jan 6, 2022
Messages
1,552
I'd appreciate if you have any code for that.
Not in a hurry. Whenever you have enough free time to check.

Thanks.
 

Josef P.

Well-known member
Local time
Today, 04:47
Joined
Feb 2, 2023
Messages
829
I think it only works with SendKeys or something similar.

Locking:

The best lock is a compiled file (accde).
 
Last edited:

isladogs

MVP / VIP
Local time
Today, 03:47
Joined
Jan 14, 2017
Messages
18,246
Danke schön @JosefP.
I knew I had answered the question before but hadn't searched for the link

@KitaYama
Although it can be done, do note the many caveats mentioned in that thread
1. It requires the use of SendKeys and the characters required are language dependant
2. VBA password protection is easily bypassed
3. Even when locked, a list of all procedures together with arguments is still accessible unless you use Option Private Module
4. Option Private Module is only available for Standard/Class Modules. A list of procedures etc in Form/Report modules is still visible.

Taken together, locking a project is of limited value and I rarely bother.
Use it as one part of a set of security measures but don't rely on it alone
 

KitaYama

Well-known member
Local time
Today, 11:47
Joined
Jan 6, 2022
Messages
1,552
@Josef P. @isladogs

I’m aware of the risks and how locking a vba project is of a limited value.
I was reading @isladogs’ security article and testing one of his demo databases.
Disabling shift by pass, hiding navigation pane and editing start up properties was done with code. I just wondered why I couldn’t find any code for locking the project.
My question was out of curiosity and not that I‘m planing to use it.

Thanks for solving the puzzle.
 

isladogs

MVP / VIP
Local time
Today, 03:47
Joined
Jan 14, 2017
Messages
18,246
The article deliberately leaves out several details. Partly because I don’t want to provide information to help hackers. I also avoid the use of SendKeys wherever possible.
 

ebs17

Well-known member
Local time
Today, 04:47
Joined
Feb 7, 2020
Messages
1,949
Counter-question: What is the special background to the desire for lock/unlock? A new front end is simply exchanged.
Design changes at runtime by the user are regularly an expression of previous deficiencies in the application.
The developer himself does not have to temporarily lock and therefore unlock anything.
 

Josef P.

Well-known member
Local time
Today, 04:47
Joined
Feb 2, 2023
Messages
829
I think it only works with SendKeys or something similar.
only :)

Just stumbled across this by accident while looking for something else in the WizHook class:
WizHook.SetVbaPassword
SendKeys is therefore not required for setting.

Looked up Thomas WizHook collection for safety:
 

isladogs

MVP / VIP
Local time
Today, 03:47
Joined
Jan 14, 2017
Messages
18,246
I wrote an updated article about the Wizhook object last year which builds on the excellent information by Thomas Moller

The Wizhook.SetVBAPassword function does allow you to set the vba project password where it is blank but it does not allow you to change an existing password. Therefore it is less useful than it could have been.
 

Users who are viewing this thread

Top Bottom