Home | Software | Microsoft Office | Microsoft Access | Create a new user in VBA Ms Access

Create a new user in VBA Ms Access

Assuming you want to create a new record in an existing Access database table named “tbl_user” with fields “user_id”, “user_cat”, and “psw”, the following VBA code should do the trick:


Sub CreateUser()

    ' Open a connection to the Access database
    Dim db As DAO.Database
    Set db = CurrentDb()
    ' Create a new record in the tbl_user table
    Dim rs As DAO.Recordset
    Set rs = db.OpenRecordset("tbl_user", dbOpenDynaset)
    ' Set the values of the new record
    rs("user_id").Value = "yourusername"
    rs("user_cat").Value = "admin"
    rs("psw").Value = "*******" 'replace *** with your password
    ' Save the new record and close the recordset and database
End Sub

To use this code, open the VBA editor in Access by pressing Alt+F11, create a new module, and paste in the code. Then, simply run the CreateUser sub to create the new record. Note that you may need to update the code to match the specific field names and data types in your database.

Share with friend(s)

Leave a Reply

Your email address will not be published. Required fields are marked *


This site uses Akismet to reduce spam. Learn how your comment data is processed.