Search code examples
sqlms-accessvbajet

ALTER USER giving Syntax Error


I'm creating my own form to allow a user to change their password in a Microsoft Access database with user-level security, an *.mdb file. When I run the following VBA code, I get error 3293: Syntax error in ALTER TABLE statement.

CurrentDb().Execute "ALTER USER user PASSWORD NewPassword OldPassword"

I'm following the instructions found in the documentation. How do we change a password through VBA?


Solution

  • CurrentDb.Execute is a DAO method, but ALTER USER must be executed from ADO.

    Dim strSql As String
    strSql = "ALTER USER user PASSWORD NewPassword OldPassword"
    CurrentProject.Connection.Execute strSql
    

    CurrentProject.Connection.Execute is an ADO method.