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?