• June 13, 2021

PHSARIT

Bring Technology Ideas with you

 Chang Password in Table of Microsoft Access using Update SQL statement

The syntax of the update statement is

UPDATE table_name
SET column1 = value1, column2 = value2, ...
WHERE condition; 

Therefore, in order to update the table in Microsoft of Access using SQL statement, first you need to have: one table and one form as below: by Go to Create –> Query Design –> SQL View

    Then write the code as below after than click on Run

    Create Table Tbl_User(User_ID int, Username varchar, Password varchar()

    Then Go to design view and you will see as below

      Go to Datasheet view –> Then insert data as below:

        By designing the form, using Combobox and Textbox include one Button and one Label as image below (please rename as your wishes)

          On Option Compare Database and Form Load Event, please enter the code as below:

          Option Compare Database
          Dim db As Database
          Private Sub Form_Load()
          Me.cboname.RowSourceType = "Table/Query"
          Me.cboname.RowSource = "select Username from Tbl_User"
          End Sub

          in Button, Change Password, please enter the code as below:

          Private Sub cmdchange_Click()
          Set db = CurrentDb
          db.Execute "Update Tbl_User Set Password='" & Me.txtnew.Value & "' where Username='" & Me.cboname.Value & "'"
          Me.lbsuc.Caption = "Your password has changed successfully"
          End Sub

          The full Code should be below:

          Option Compare Database
          Dim db As Database
          Private Sub cmdchange_Click()
          Set db = CurrentDb
          db.Execute "Update Tbl_User Set Password='" & Me.txtnew.Value & "' where Username='" & Me.cboname.Value & "'"
          Me.lbsuc.Caption = "Your password has changed successfully"
          End Sub
          
          Private Sub Form_Load()
          Me.cboname.RowSourceType = "Table/Query"
          Me.cboname.RowSource = "select Username from Tbl_User"
          End Sub
          

          The Go to View –> Select your Combobox, then type a new password, it will look like this ( Let say, I update password the user Apple which is 123 to apple123)

            Go to your table, then you will see:

              Related post