bentheimmigrant
Lost & confused
- Local time
- Today, 05:43
- Joined
- Aug 21, 2015
- Messages
- 60
I'm writing a sub to cycle through all the controls on all the forms in a project, and export their properties to csv.
This has gone smoother than expected (hat-tip: http://vbcity.com/forums/p/142594/609960.aspx#609960)
Now, I am going through and cycling all the properties, but each ControlType (which is an integer) has a different number of properties, so I have to write a separate line of headers for each type.
Unfortunately, the ControlType's are accessed in a seemingly random order. Now, if I could sort by ControlType, I could then only put one header line in for each type of control.
Questions:
1. Is there a way to do this that won't make my head explode?
2. A simpler question: Does anyone have a link converting ControlType to the Actual control type (e.g. 100 = label)?
Code below. (Note: The "Write #1, "End"" bits are because I need to close out a line that has a comma, and I don't want an extra line return... not sure if that's logical, but it works).
This has gone smoother than expected (hat-tip: http://vbcity.com/forums/p/142594/609960.aspx#609960)
Now, I am going through and cycling all the properties, but each ControlType (which is an integer) has a different number of properties, so I have to write a separate line of headers for each type.
Unfortunately, the ControlType's are accessed in a seemingly random order. Now, if I could sort by ControlType, I could then only put one header line in for each type of control.
Questions:
1. Is there a way to do this that won't make my head explode?
2. A simpler question: Does anyone have a link converting ControlType to the Actual control type (e.g. 100 = label)?
Code below. (Note: The "Write #1, "End"" bits are because I need to close out a line that has a comma, and I don't want an extra line return... not sure if that's logical, but it works).
Code:
Sub Export_Control_Details()
Dim objForm As AccessObject
Dim objActiveForm As Form
Dim objControl As Control
Dim intCounter As Integer
Dim prp As Property
Dim ExPath As String, ExFile As String
Dim prpHeaders As Boolean
Dim prpVal As String
Dim ControlType As Long
ExPath = CurrentProject.Path
If Not Right(ExPath, 0) = "\" Then
ExPath = ExPath & "\"
End If
ExPath = ExPath & "Control Export\"
If Dir(ExPath, vbDirectory) = "" Then
MkDir (ExPath)
End If
For intCounter = 0 To Application.CodeProject.AllForms.Count - 1
Set objForm = Application.CodeProject.AllForms.Item(intCounter)
DoCmd.OpenForm FormName:=objForm.Name, View:=acDesign
ExFile = ExPath & objForm.Name & ".csv"
Open ExFile For Output As #1
' Reset the control type
ControlType = 0
Set objActiveForm = Application.Screen.ActiveForm
For Each objControl In objActiveForm.Controls
If ControlType <> objControl.Properties("ControlType") Then
ControlType = objControl.Properties("ControlType")
Write #1, vbCrLf
Write #1, vbCrLf
Write #1, "Control Type: " & ControlType
Write #1, vbCrLf
' Reset the headers flag to get new line of headers
prpHeaders = False
End If
If Not prpHeaders Then
Write #1, "Control Name",
For Each prp In objControl.Properties
Write #1, prp.Name,
Next prp
Write #1, "End"
End If
prpHeaders = True
Write #1, objControl.Name,
For Each prp In objControl.Properties
On Error Resume Next
prpVal = prp.Value
If Err.Number <> 0 Then
prpVal = ""
Err.Clear
End If
Write #1, prpVal,
Next prp
Write #1, "End"
Next
DoCmd.Close ObjectType:=acForm, ObjectName:=objActiveForm.Name
Close #1
Next
Set objForm = Nothing
Set objActiveForm = Nothing
Set objControl = Nothing
End Sub