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)





By the way, if you got or are getting value from the VBA information, please give me a tip, thanks!


These posts may help answer your question too...

How can I interact with other Office applications (Excel) using VBA in Access?

Need to write your Access data or query to an Excel file? Here is the how to do it: Most people are familiar with Excel and know how to use it well (enough), and when you start talking about Access, they get scared off, and don’t know what to do anymore. Well, here you are […]

How To Generate A XML File With Access VBA

XML is used to structure your data. You can send a CSV file to another person, but using XML, you can structure your data in a more elegant format, and get very specific about your fields, and what data is contained within your tags (your field names). This is different than a basic CSV file […]

Mouse Click Counter On Access Form

This post will demonstrate how you can count the number of clicks on your button in a certain time frame. It will function like a game . Here is the database form all in one: Option Compare Database Public m_dteStartTime As Date Public m_dteStopTime As Date Private Sub btnClicker_Click() Dim intValue As Integer Dim rst […]

Shared Access Database Management

Here is a handy setup for those who need to manage a shared access database. Either you can create this from scratch as per the example or add the new tables to your existing database. This setup will track: 1. the users currently using the database 2. what time the user and computer name currently […]

Previous Post

Passing Form Field Default Values

Next Post

Recordset In VBA – PT3

Leave a Reply

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