Access.2007.VBA.Bibl..

(John Hannent) #1

First, clear data from the old table of table and field names:


strTable = “zstblTableAndFieldNames”
strReport = “zsrptTableAndFieldNames”
DoCmd.SetWarnings False
strSQL = “DELETE * FROM “ & strTable
DoCmd.RunSQL strSQL

Fill the table with table and field names, iterating through the database’s TableDefs collection:


Set dbs = CurrentDb
Set rst = dbs.OpenRecordset(strTable, dbOpenTable)

For Each tdf In dbs.TableDefs
strTable = tdf.Name
If Left(strTable, 4) <> “MSys” Then
Set flds = tdf.Fields
For Each fld In flds
strFieldName = fld.Name
With rst
.AddNew
!TableName = strTable
!FieldName = strFieldName
!DataType = fld.Type
!ValidationRule = fld.ValidationRule
!Required = fld.Required
.Update
End With
Next fld
End If
Next tdf

rst.Close

DoCmd.OpenTable strTable

strTitle = “Table filled”
strPrompt = “Print report now?”
intReturn = MsgBox(strPrompt, vbQuestion + vbYesNo, _
strTitle)
If intReturn = vbYes Then
strReport = “zsrptTableAndFieldNames”
DoCmd.OpenReport strReport
End If

ErrorHandlerExit:
Exit Sub

Customizing the Ribbon with XML in Access Databases and Add-ins 15

Free download pdf