Solved

Reset user's password VBA

Posted on 2009-05-14
10
535 Views
Last Modified: 2012-05-07
How can I reset a user's password using VBA. I want my admins to be able to do this through a button click on a form.

I considered:
DBEngine.Workspaces(0).Users(username).NewPassword

But for that to work you need to have the user's old password and you can't just use
DBEngine.Workspaces(0).Users(username).Password
to get it.
0
Comment
Question by:bejhan
  • 4
  • 3
  • 3
10 Comments
 
LVL 57

Accepted Solution

by:
Jim Dettman (Microsoft MVP/ EE MVE) earned 125 total points
ID: 24387664
<<DBEngine.Workspaces(0).Users(username).NewPassword>>
  You don't need to have the old password, but you do need to be a member of the admins group.
JimD.
0
 
LVL 75
ID: 24387674
Basically this:

Public Function SSF_PwdCtl() As Boolean
   

' all code from experts exchange
    'Dim WS As DAO.Workspace
    Dim sDbName As String
    Dim sPwdOld As String
    Dim sPwdNew As String
    Dim db As DAO.Database

    sDbName = "C:\SomeApp.mdb"
    sPwdOld = InputBox("Old Pwd: ")
    sPwdNew = InputBox("New Pwd:")

   
    Set db = DBEngine.Workspaces(0).OpenDatabase(sDbName, options:=True, readonly:=False, Connect:=";PWD=" & sPwdOld & ";")
   
    db.NewPassword sPwdOld, sPwdNew
   
    MsgBox "Pwd Accepted"
    Set db = Nothing
    SSF_PwdCtl = True

End Function

mx
0
 
LVL 75
ID: 24387680
I assume you are referring to the database password ?

mx
0
 
LVL 57
ID: 24387688
FYI, you don't need the old password and I should have been clearer; when your part of the admins group, you can pass an empty string for either the old or new password argument.
JimD.
0
 
LVL 1

Author Comment

by:bejhan
ID: 24389852
JDettman that's perfect thanks.

Also I was wondering if there is a way to detect if a user's password is blank?
0
Free Gift Card with Acronis Backup Purchase!

Backup any data in any location: local and remote systems, physical and virtual servers, private and public clouds, Macs and PCs, tablets and mobile devices, & more! For limited time only, buy any Acronis backup products and get a FREE Amazon/Best Buy gift card worth up to $200!

 
LVL 75
ID: 24389904
Seems in the code I posted ... if I didn't supply the old password, it did not work.  And ... you certainly have to do that if you are doing it manually ... and I would hope so, otherwise anyone could change the password.  Again, I'm talking about the database password, not ULS.

Are you ?

mx
0
 
LVL 1

Author Comment

by:bejhan
ID: 24389917
Oh sorry MX forgot to reply to you, I was referring to ULS.
0
 
LVL 75
ID: 24389924
ok ... then ignore what I said.

mx
0
 
LVL 57
ID: 24394744
<<Also I was wondering if there is a way to detect if a user's password is blank?>>
  Only way I can think of doing that is to attempt to open a workspace object for that user with a blank password and see if it errors or not.
JimD.
0
 
LVL 1

Author Comment

by:bejhan
ID: 24398553
Ah, I never even thought of that. Works perfect. Previous to this I was making an entry in my user log about setting a password and having to remove it when the password was reset. Not a solution I was happy with.
0

Featured Post

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

When you are entering numbers in a speadsheet, and don't remember what 6×7 is, you just type “=6*7" instead. It works in every cell! This is not so in Access. To enter the elusive 42 in a text box, you have to find a calculator, and then copy the re…
Introduction The Visual Basic for Applications (VBA) language is at the heart of every application that you write. It is your key to taking Access beyond the world of wizards into a world where anything is possible. This article introduces you to…
In Microsoft Access, learn the trick to repeating sub-report headings at the top of each page. The problem with sub-reports and headings: Add a dummy group to the sub report using the expression =1: Set the “Repeat Section” property of the dummy…
With Microsoft Access, learn how to specify relationships between tables and set various options on the relationship. Add the tables: Create the relationship: Decide if you’re going to set referential integrity: Decide if you want cascade upda…

747 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now