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_dao()
' 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 ntbl As DAO.TableDef
Dim fld As DAO.Field
Dim rcd As DAO.Recordset
Dim stra As String
On Error Resume Next
'close the table if open
DoCmd.Close acTable, "formnames", acSaveYes
On Error Resume Next
' delete table tblnames if exists
CurrentDb.TableDefs.Delete "formnames"
' create table with table name tblnames
Set ntbl = CurrentDb.CreateTableDef("formnames")
Set fld = ntbl.CreateField("Form_Name", dbText, 255)
ntbl.Fields.Append fld
CurrentDb.TableDefs.Append ntbl
RefreshDatabaseWindow
For Each obj In dbs.AllForms
Set rcd = CurrentDb.OpenRecordset("formnames", dbOpenDynaset, dbAppendOnly)
With rcd
.AddNew
.Fields![Form_name].Value = obj.Name
.Update
.Close
End With
Next
DoCmd.SetWarnings (True)
End Sub
Download Access Database
No comments:
Post a Comment