Add, Delete, Update using SQL VBA Code



Insert Command

To insert data to a specific field using "Update" option to a table directly from a form, use the following code:



DoCmd.RunSQL "INSERT INTO TABLE1 (FIELD1, FIELD2) " & _
"VALUES ('SOME TEXT', 'SOME TEXT')"

Update Command

To update the database directly from a form, use the following code:


DoCmd.RunSQL "UPDATE Table1 SET [Field1]= " & me.text1 & _
", [Field2]= " & me.text2 & " WHERE [Field3]= '" & me.text3 & "';"

Delete Command

To delete all data from a specific table, use the following code:


DoCmd.RunSQL "DELETE * FROM Table1"

To delete specific data from a table, use the following code:


DoCmd.RunSQL "DELETE * FROM Table1 WHERE Field1='" & me.text1 & "';"



0 تعليقات

إرسال تعليق

Post a Comment (0)

أحدث أقدم