Open protected Mdb file from another file using VBA

A

AviA

I am trying to build a VB code that will open from one access form, another
access mdb/mde file, in a new window.
The point is that the other file is protected with ms access password, and I
wish that the VB code will supply the password to the opened file, without
the intervention of the end user.

(That is, if the user will press a button from one mdb file, he will be
automatically connected to the other protected mdb file. If he will try to
open directly the other protected file, a password request will appear)

Could you please help me with this one?
 
A

Alex Dybenko

Hi,
you can create new access instance via automation, using CreareObject() and
then open database these using OpenDatabase Method, where you can supply
password:

OpenDatabase("c:\my.mdb", False, False, ";pwd=mypassword")

HTH
 
D

David Lloyd

Just a point of clarification. The OpenDatabase method, while returning an
instance of a Database object, will not actually open the database in a new
database window. To open the database in a new window, you would use the
OpenCurrentDatabase method. The methods are similar, however, they do have
this distinction.

Another important consideration is with the Access Application object. When
declared within a subroutine (or function), the instance of Access will
close at the end of the subroutine (or function). To avoid this use a
module level declaration.

The following is a simple example of a form module with a command button
used to open the database in a new window. The automation security level is
adjusted to avoid the security warning dialog box. In this example, the
instance of the Access Application object is destroyed in the form Close
event.

Option Compare Database
Option Explicit
Dim acc As New Access.Application

Private Sub Command0_Click()
Dim accAutoSec As MsoAutomationSecurity

On Error GoTo Errorhandler

'Capture current security setting
accAutoSec = acc.AutomationSecurity

'Reset the security to low temporarily to avoid the security warning
acc.AutomationSecurity = msoAutomationSecurityLow

'Open the database
acc.OpenCurrentDatabase "C:\db2.mdb", False, "mypassword"

'Make the application visible
acc.Visible = True

'Reset the security level
acc.AutomationSecurity = accAutoSec

Exit_Sub:

Exit Sub

Errorhandler:
If Err.Number <> 0 Then
MsgBox Err.Description, vbOKOnly, "Error"
Resume Exit_Sub
End If
End Sub

Private Sub Form_Close()
Set acc = Nothing

End Sub

--
David Lloyd
MCSD .NET
http://LemingtonConsulting.com

This response is supplied "as is" without any representations or warranties.


I am trying to build a VB code that will open from one access form, another
access mdb/mde file, in a new window.
The point is that the other file is protected with ms access password, and
I
wish that the VB code will supply the password to the opened file, without
the intervention of the end user.

(That is, if the user will press a button from one mdb file, he will be
automatically connected to the other protected mdb file. If he will try to
open directly the other protected file, a password request will appear)

Could you please help me with this one?
 
A

AviA via AccessMonster.com

Thank you very much for your help, I've tried your vb Code and it's working
just like I wanted it to be.

One problem – it seems that my access can't support * MSO *.
What I did is to cancel those lines.
The question is if there is a way to support MSO?

thank you again,

AviA
 

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