MS Access Add Delete Update Using VBA Code are few entries that are needed mostly by Microsoft Access programmers where almost all access programs must contains these VBA codes. However, this method is only applied to Microsoft Access Database.
Access Add Delete Update Using VBA Code Commands:
Insert Command
The following VBA Code will append new data or text to any of your tables which at the end will be reflected in your form. To insert data to a specific table from a form, just use the below VBA as an example:
DoCmd.RunSQL "INSERT INTO TABLE1 (FIELD1, FIELD2) " & _
"VALUES ('SOME TEXT', 'SOME TEXT')"
Update Command
Similarly, the below example will update the database directly from a form. Just use the below VBA code as an example:
DoCmd.RunSQL "UPDATE Table1 SET [Field1]= " & me.text1 & _
", [Field2]= " & me.text2 & " WHERE [Field3]= '" & me.text3 & "';"
Delete Command
Finally, you might need to either delete all fields from a table or just a specific field. Moreover, below are two examples, so you can use either upon your need:
DoCmd.RunSQL "DELETE * FROM Table1"
To delete specific data from a table, use the following VBA code:
DoCmd.RunSQL "DELETE * FROM Table1 WHERE Field1='" & me.text1 & "';"
Please refer to Microsoft Access for more details.