Pages

Monday, December 26, 2011

Get Names of all the Forms Existing in a Database and Add them to a New Table Using Query

If you want to know the find the names of all forms existing in the database and add them to new table.

Here is the code-


Sub create_a_new_table_and_add_all_form_names_using_query()
' add all FORM names existing in a databse to a new table called FORMnames
DoCmd.SetWarnings (False)
Dim obj As AccessObject, dbs As Object
Set dbs = Application.CurrentProject
Dim stra As String
On Error Resume Next
'close the table if open
DoCmd.Close acTable, "formnames", acSaveYes
' delete table tblnames if exists
On Error Resume Next
DoCmd.RunSQL "drop TABLE formnames "
' create table with table name tblnames
DoCmd.RunSQL "CREATE TABLE formnames (Form_Name Text)"
' adding table names in to tblnames
For Each obj In dbs.AllForms
stra = "INSERT INTO formnames ([Form_Name]) values(' " & obj.Name & "')"
DoCmd.RunSQL stra
Next
DoCmd.SetWarnings (True)
End Sub

Download Access Database

No comments:

Post a Comment