Twitter
LinkedIn
YouTube
RSS
Facebook

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 | Completed! VBA Class! >>

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


Sign Up For A FREE MS Access VBA Video Tutorial Subscription. You will get over 27 tutorial videos that will help you do your job better! Start Yours Now At:
http://vbahowto.com/ms-access-tutorial

Helpful? Consider giving us a tip. Thanks!

($5 suggested amount)




Want All The Access Videos?, Click Here!

Learn to program



Need help? Click and Call LoeblCom Services



Leave a Reply

You must be logged in to post a comment.