Error with OpenCurrentDatabase

infinitx

Registered User.
Local time
Today, 06:42
Joined
Mar 22, 2004
Messages
63
Hi,

I get the following error message and it highlights the following code when I use this module:

Code:
Option Compare Database
Option Explicit
Private Declare Function apiShowWindow Lib "user32" _
Alias "ShowWindow" (ByVal hwnd As Long, _
ByVal nCmdShow As Long) As Long
Function OpenPasswordProtectedDB() As Boolean
Static acc As Access.Application
Dim Lox As Long

Lox = apiShowWindow(hWndAccessApp, 2)

Set acc = New Access.Application
    acc.Visible = True
    acc.OpenCurrentDatabase CurrentProject.Path & "\" & "Access.mdb", , "password"
    OpenPasswordProtectedDB = True

End Function


Code it Highlights

Where it says "acc.OpenCurrentDatabase", it highlights the OpenCurrentDatabase portion.


Error Message

"Compile Error: Wrong number of arguments or invalid property assignment"


I only get this error message when using Access 97. When I use Access XP, it works fine.


What might the problem be?


Thank you very much,
Alex
 
The OpenCurrentDatabase method changed between A97 and A2K

A97 - Uses two arguments, filepath and exclusive

application.OpenCurrentDatabase dbname[, exclusive]

dbname is the filepath of the access application (Type String), and exclusive is the boolean whether you want the db to open in exclusive mode (optional; if not included then exclusive is false)

A2K - Uses three arguments, filepath, exclusive, and password

expression.OpenCurrentDatabase(filepath, Exclusive, bstrPassword)

This is the one you are currently using.

For your code to work with A97, you have to remove the password argument. I'm not sure if the password is handled through another method in A97, but you can't use it in the OpenCurrentDatabase method as you are currently doing with the updated version of Access
 
I don't know, but a little followup, I think that the currentproject object (member of the access application object), became available in Access 2000.

Could you try using currentdb.name in stead (you'll have to strip of the db name a the end of the string, though)
 

Users who are viewing this thread

Back
Top Bottom