SQL- Update Statement
The SQL Update Statement is the SQL code that used to updatet the existing data in a database. It will be used in combination of other VB code. There are few examples of using the SQL –Update Statement below.
SQL UPDATE Syntax
Update a specific record in table:
UPDATE table_name SET field_name = some_value WHERE field_name = some_value;
#1 Update certain Field on Specific Record
The Update command can be put under the click button to Update a record that is selected from a List Box.
VB Code under a Save button:
Private Sub cmdSave_Click() ' submit button On Error GoTo ErrHandler: Dim strUpdate As String Me.Refresh If IsNull(Me.Password) Then MsgBox "Please enter a new password!", vbInformation, "Data Required!" Else strUpdate = "UPDATE tblUser SET Password = '" & Me.Password.Value & "'" _ & "WHERE (UserID = " & Me.UserID & ")" DoCmd.SetWarnings False DoCmd.RunSQL strUpdate DoCmd.SetWarnings True MsgBox "Updated new password successfully", vbInformation, "Password Updated" Exit Sub End If Exit_ErrHandler: Exit Sub ErrHandler: MsgBox Err.Description, vbCritical Err.Clear End Sub