Loop through the controls on a form, showing names and properties using DAO in VBA
Option Compare Database
Option Explicit
'Constants for examining how a field is indexed.
Private Const intcIndexNone As Integer = 0
Private Const intcIndexGeneral As Integer = 1
Private Const intcIndexUnique As Integer = 3
Private Const intcIndexPrimary As Integer = 7
Function ShowFormProperties(strFormName As String)
On Error GoTo Err_Handler
'Purpose: Loop through the controls on a form, showing names and properties.
'Usage: Call ShowFormProperties("Form1")
Dim frm As Form
Dim ctl As Control
Dim prp As Property
Dim strOut As String
DoCmd.OpenForm strFormName, acDesign, WindowMode:=acHidden
Set frm = Forms(strFormName)
For Each ctl In frm
For Each prp In ctl.Properties
strOut = strFormName & "." & ctl.Name & "." & prp.Name & ": "
strOut = strOut & prp.Type & vbTab
strOut = strOut & prp.Value
Debug.Print strOut
Next
If ctl.ControlType = acTextBox Then Stop
Next
Set frm = Nothing
DoCmd.Close acForm, strFormName, acSaveNo
Exit_Handler:
Exit Function
Err_Handler:
Select Case Err.Number
Case 2186:
strOut = strOut & Err.Description
Resume Next
Case Else
MsgBox "Error " & Err.Number & ": " & Err.Description, vbExclamation, "ShowFormProperties()"
Resume Exit_Handler
End Select
End Function
No comments:
Post a Comment