1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70
| Option Compare Database
Option Explicit
'--- adapté de
'--- https://stackoverflow.com/questions/34901810/microsoft-access-loop-through-all-forms-and-controls-on-each-form
Public Sub GetForms()
Dim oForm As Form
Dim nItem As Long
Dim bIsLoaded As Boolean
For nItem = 0 To CurrentProject.AllForms.Count - 1
bIsLoaded = CurrentProject.AllForms(nItem).IsLoaded
If Not bIsLoaded Then
On Error Resume Next
DoCmd.OpenForm CurrentProject.AllForms(nItem).Name, acDesign
End If
Set oForm = Forms(CurrentProject.AllForms(nItem).Name)
GetControls oForm
If Not bIsLoaded Then
On Error Resume Next
DoCmd.Close acForm, oForm.Name
End If
Next
End Sub
Sub GetControls(ByVal oForm As Form)
Dim oCtrl As Control
Dim cCtrlType, cCtrlCaption As String
Debug.Print "----- "; oForm.Name
For Each oCtrl In oForm.Controls
If oCtrl.ControlType = acSubform Then Call GetControls(oCtrl.Form)
Select Case oCtrl.ControlType
Case acLabel
cCtrlType = "label"
cCtrlCaption = oCtrl.Caption
Case acCommandButton
cCtrlType = "button"
cCtrlCaption = oCtrl.Caption
Case acTextBox
cCtrlType = "textbox"
'cCtrlCaption = oCtrl.Properties("DataSheetCaption")
cCtrlCaption = "---"
'--- ajout d'un trait sous le textbox
'--- 1 cm = 567 twips => 1 mm = 57 twips
'Debug.Print oCtrl.Left, oCtrl.Top, oCtrl.Width, oCtrl.Height
'CreateControl oForm.Name, acLine, acDetail, , , oCtrl.Left, oCtrl.Top + oCtrl.Height + 57, oCtrl.Width, 0
'--- style fond + format conditionnel si actif
oCtrl.BackStyle = 0 '--- 0=transparent, 1=standard
If oCtrl.FormatConditions.Count > 0 Then
oCtrl.FormatConditions.Item(0).Delete '--- supprime le 1er format conditionnel
End If
oCtrl.FormatConditions.Add acFieldHasFocus
oCtrl.FormatConditions.Item(0).BackColor = vbYellow
Case acComboBox
cCtrlType = "ComboBox"
cCtrlCaption = "---"
'--- style fond + format conditionnel si actif
oCtrl.BackStyle = 0 '--- 0=transparent, 1=standard
If oCtrl.FormatConditions.Count > 0 Then
oCtrl.FormatConditions.Item(0).Delete '--- supprime le 1er format conditionnel
End If
oCtrl.FormatConditions.Add acFieldHasFocus
oCtrl.FormatConditions.Item(0).BackColor = vbYellow
Case Else
cCtrlType = "Type " & oCtrl.ControlType
cCtrlCaption = "---"
End Select
Debug.Print oForm.Name, oCtrl.Name, cCtrlType, cCtrlCaption
Next
End Sub |
Partager