Results 1 to 4 of 4
  1. #1
    smartflashes is offline Novice
    Windows XP Access 2003
    Join Date
    Jan 2012
    Posts
    12

    Help fixing a code to change password programatically

    I'm trying to change a password for a .mde file programatically. I used the code provided by Mircosoft but it doesn't work and always gives me an error message that "Sub or Function not defined". Here is the link for reference:


    http://msdn.microsoft.com/en-us/libr...urity_password

    Here is the code:
    Code:
    Private Function ChangeDBPassword(ByVal OldPassword As String, _
            ByVal NewPassword As String, ByVal Path As String) As Boolean
        Dim objConn as ADODB.Connection
        Dim strAlterPassword as String
    
        On Error GoTo ChangeDBPassword_Err
    
        ' Create the SQL string to change the database password.
        strAlterPassword = "ALTER DATABASE PASSWORD [123] [abc];"
    
        ' Open the secured database.
        Set objConn = New ADODB.Connection
        With objConn
            .Mode = adModeShareExclusive
            .Provider = "Microsoft.Jet.OLEDB.4.0"
            .Properties("Jet OLEDB:Database Password") = "OldPassword"
            .Open "Data Source=[c:\data\db1.mde];" 
    
            ' Execute the SQL statement to change the password.
            .Execute (strAlterPassword)
        End With
    
        ' Clean up objects.
        objConn.Close
        Set objConn = Nothing 
    
        ChangeDBPassword = True
    
    ChangeDBPassword_Err:
        Msgbox Err.Number & ":" & Err.Description
        ChangeDBPassword = False 
    End Function

  2. #2
    June7's Avatar
    June7 is online now VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,825
    Did you put the code behind a form or general module? Where do you call the function?
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    smartflashes is offline Novice
    Windows XP Access 2003
    Join Date
    Jan 2012
    Posts
    12
    Quote Originally Posted by June7 View Post
    Did you put the code behind a form or general module? Where do you call the function?
    I just call the function in the immediate window as explained at the microsoft page. Do you have any other suggestions?? By the way someone suggested the following:

    Replacing the line

    strAlterPassword = "ALTER DATABASE PASSWORD [Your NewPassword] [Your OldPassword];"
    by

    strAlterPassword = "ALTER DATABASE PASSWORD '" & NewPassword & "' '" & OldPassword & "';"

    and the line

    .Open "Data Source=[Your Path];"
    by

    .Open "Data Source=" & Path & ";"
    Then try it again.

    Calling this function by passing it the 3 parameters: OldPassword, NewPassword and Path. Calling the function (when public) in the immediate window exactly the same way you examine a variable. Intellisense should then give you the parameters you have to enter. It should look similar to following:

    ? ChangeDBPassword("foo", "bar", "c:\data\test.mdb")

    But the code still does not work.

  4. #4
    June7's Avatar
    June7 is online now VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,825
    Change Private to Public.

    I agree with those changes if you want to pass the values as arguments. The alternative is to remove the arguments from the function (or make them Optional) and hard code the values. I think you were hard coding so the arguments were not needed and if you don't want the function to demand you do the input anyway, remove the arguments.

    Also, don't know if the Jet reference is correct for Access 2003.

    That code sample does appear flawed.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Change Password form
    By turbo910 in forum Forms
    Replies: 16
    Last Post: 05-07-2015, 09:02 AM
  2. Change password form
    By funkygoorilla in forum Forms
    Replies: 8
    Last Post: 01-17-2012, 08:37 PM
  3. Change Password Form using VBA
    By anwaar in forum Programming
    Replies: 2
    Last Post: 09-02-2011, 01:29 PM
  4. Password change issues
    By westeral in forum Access
    Replies: 0
    Last Post: 11-28-2009, 09:20 AM
  5. Change from old password to new password
    By richy in forum Security
    Replies: 0
    Last Post: 11-17-2005, 05:05 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums