Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

change password via vba

Status
Not open for further replies.

sramey00

Programmer
Jun 9, 2004
149
US
I am on the right track here, however i can't get the database to open exclusively to allow password changes.

can any point in the right direction?

Code:
On Error GoTo errorhandler

Dim strDbName As String
Dim strOLDDB As String
Dim strNewDb As String
Dim y As Integer

Dim acc As New Access.Application
Dim db As DAO.Database


strDbName = Dir(oldDbPath & "\*.MDB")   ' Retrieve the first MDB file entry.

'Loop though the files in the folder to find MDB files.
Do While strDbName <> ""
' Ignore the current folder and the encompassing folder.
  If strDbName <> "." And strDbName <> ".." Then

    If Right(strDbName, 3) = "mdb" Then

       Set acc = New Access.Application

        acc.Visible = False
    
        Set db = acc.DBEngine.OpenDatabase(oldDbPath & "\" & strDbName, False, False, "MS ACCESS;PWD=level1") '
        'Error message for previous line: -2147221163 Method 'DBEngine' of object '_Application' failed
        
       
        acc.OpenCurrentDatabase oldDbPath & "\" & strDbName, True, "level1"
        'should open exlusively, but doesn't... (path, exclusive, bstrPassword)
        
     
        CurrentDb.NewPassword "level1", "" 'change database password. can't unless db opened as exclusive.

        CurrentDb.Close
        Set acc = Nothing
        acc.Quit

        
    End If
  End If
strDbName = Dir    ' Get next MDB.
Loop
MsgBox "errors: " & y

Exit Sub

errorhandler:
    Call writeError(strDbName, Err.Number, Err.Description)
    y = y + 1


Resume Next

thanks!

Mr. Steve

 
Exerpt from the help file:
In the DAO listing the second two parameters to the OpenDatabase method indicate exclusive and read-only access respectively.
Code:
Set db = acc.DBEngine.OpenDatabase(oldDbPath & "\" & strDbName, [b]True[/b], False, "MS ACCESS;PWD=level1")

Hope this helps,
CMP

(GMT-07:00) Mountain Time (US & Canada)
 
i tried what changing it to true, but i still recieved the error of

'Error message for previous line: -2147221163 Method 'DBEngine' of object '_Application' failed




Mr. Steve

 
Just to make sure we are starting at step 1, is the database that you are trying to open when you get the error in use by anyone else when you are trying to open it?

If someone else has the database open you cannot open it exclusively. Check to see if there is a file in the same directory with the same name and an .ldb extension.

CMP

(GMT-07:00) Mountain Time (US & Canada)
 
no one has it open and there is no ldb file in the directory.

this problem has been troubling me all day!!

when i comment out the code line:
Code:
Set db = acc.DBEngine.OpenDatabase(oldDbPath & "\" & strDbName, False, False, "MS ACCESS;PWD=level1")

the only error i receive is the
"can't change password on shared db"

i am passing the correct parameters to the function, correct?

Mr. Steve

 
Yes as far as I can tell.

(GMT-07:00) Mountain Time (US & Canada)
 
found this on a different message board as to why i was getting the dbengine error...

manually registered the dll and it stopped the error.

Hi,

I believe you are getting the "Method 'DBEngine' of object '_Application' failed" error because there is a problem with your DAO installation. If you manually register the dao360.dll, you should no longer experience this issue when you attempt to use the Exporter tool.

Execute :
Regsvr32 "C:\Program Files\Common Files\Microsoft Shared\DAO\dao360.dll"

Please refer to the following article for detailed steps:

If this does not resolve your issue, please let me know.

I hope this helps.
Regards,
Hilary
 
figured it out!!!

these two lines needed to be changed...
Code:
CurrentDb.NewPassword "level1", "" 'change database password. can't unless db opened as exclusive.

        CurrentDb.Close

needs to be changed to:
Code:
ACC.CurrentDb.NewPassword "level1", "" 'change database password. can't unless db opened as exclusive.

        ACC.CurrentDb.Close

hope this script helps!

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top