How to Delete From a Table In-Access With Visual Basic
Visual Basic is a compiler language used to create desktop and web applications. One part of serving dynamic content to users is a database back-end. Microsoft Access is a database back-end used in small-to-medium-sized businesses. The database software holds tables and stored procedures that contain and manipulate the data used in your applications. You can delete a table in Access from your application using Visual Basic.
Instructions
-
-
1
Open the Visual Basic application. Double-click the web or Windows form to open the design viewer. Right-click the form and select "View Code." This brings you to the code view.
-
2
Open the database and the table definition object. The table definition object has the function available to delete a table from Access. The code below shows you how to open a database and assign the table definitions to a variable:
Set accessTable = OpenDatabase("C:\myDB.mdb")
Set tds = accessTable.TableDefs -
-
3
Call the Access table definition function to delete the table. This function deletes the object and the data contained within the table. The code below illustrates how to call the function:
accessTable.TableDefs.Delete <myTable>
Replace "<myTable>" with the name of the Access table. -
4
Save the file and press the F5 key. This runs your application in the debugger, so you can test the code.
-
1
Tips & Warnings
Once you delete a table, all the data is destroyed as well. Make sure you take a backup of the Microsoft Access file before delete a table from it.
References
- Photo Credit data disk image by sumos from Fotolia.com