Recordset In VBA – PT4

This video will show you how to create the SQL recordset in VBA.

SQL is used to perform updates quickly to a data source. The 4 main SQL statements cover the “action” queries in MS Access:

1. SELECT
2. UPDATE
3. DELETE
4. INSERT

1. The syntax for the SELECT is:

SELECT [field] FROM [table]

2. The syntax for the UPDATE is:

UPDATE [table] SET [field] = [value]

3. The syntax for the DELETE is:

DELETE FROM [table] WHERE [field] = [value]

4. The syntax for the INSERT is:

INSERT INTO [table] ([field]) VALUES ([value])

This video shows how to use a SQL Recordset In VBA to SELECT records from a table, and UPDATE a record in the table.

Private Sub Form_Load()
    'Customize this when you want to have more control over the form's workings.
        
        
    Dim strSQL As String
    
    strSQL = "SELECT * FROM Customers WHERE CompanyName Like 'W*'"
        
    'Set the recordsource to the "Customer" table
    Me.RecordSource = strSQL
    Set m_rst = Me.RecordsetClone
    
End Sub


Private Sub btnUpdate_Click()
    Dim strSQL As String
    
    strSQL = "UPDATE Customers SET `CompanyName` = '" & Me.txtCustomerName & "' "
    strSQL = strSQL & " WHERE `CustomerID`= '" & Me.txtCustomerID & "'"
    
    CurrentDb.Execute strSQL
    
    MsgBox "Updated Name To: " & Me.txtCustomerName
End Sub



<< Recordset Navigation | Solidify your new education. >>

CONGRATULATIONS! YOU HAVE FINISHED THE VBA PROGRAMMING TUTORIAL TRAINING COURSE!

I recommend that you continue your education and solidify your learning by going to our online store and getting the learning guide and complete database for topics you have interest in.

Here are a few of our learning guides you may be interested in:

Donors And Donations Tracking Database

– Customers And Orders Tracking Database (Coming Soon)

Several Others (Coming Soon)



Leave a Reply