How do I use Dev Ashish's Code?


Tony Williams

I want to print a list of controls on a form and it seems I can use this
code from Dev Ashish but not being a VB expert I'm not sure how to. The web
site says "pass the form name to code". How do I do that? My form is called
"frmfdainput" When I do that do I paste this code inot the immediate window
and then press enter? I did try this but got an error message that said
"Compile error Invalid in Immediate pane" How do I then print a hard copy?
Here is Dev's code
************ Code Start ***************
' This code was originally written by Dev Ashish.
' It is not to be altered or distributed,
' except as part of an application.
' You are free to use it in any application,
' provided the copyright notice is left unchanged.
' Code Courtesy of
' Dev Ashish
Function fEnumControls(ByVal strfrmToEnum As String)
'prints out control's Type and Name
'will NOT enumerate controls within an embedded subform
Dim astrCtlName() As String
Dim i As Integer, intCnt As Integer
Dim frm As Form
'Un-Comment the next two lines for Access 95
'Const acPage = 124
'Const acTabCtl = 123
'if form is closed, exit function
If Not fIsLoaded(strfrmToEnum) Then
MsgBox "Form " & strfrmToEnum & " is probably closed!! " & _
vbCrLf & "Please open it & try again.", vbCritical
Exit Function
End If

Set frm = Forms(strfrmToEnum)
'Count the number of controls
intCnt = frm.Count

'Initialize the array to hold control names
ReDim astrCtlName(0 To intCnt - 1, 0 To 1)

For i = 0 To intCnt - 1
astrCtlName(i, 0) = frm(i).Name
'Use ControlType to determine the Type of Control
Select Case frm(i).ControlType
Case acLabel: astrCtlName(i, 1) = "Label"
Case acRectangle: astrCtlName(i, 1) = "Rectangle"
Case acLine: astrCtlName(i, 1) = "Line"
Case acImage: astrCtlName(i, 1) = "Image"
Case acCommandButton: astrCtlName(i, 1) = "Command Button"
Case acOptionButton: astrCtlName(i, 1) = "Option button"
Case acCheckBox: astrCtlName(i, 1) = "Check box"
Case acOptionGroup: astrCtlName(i, 1) = "Option group"
Case acBoundObjectFrame: astrCtlName(i, 1) = "Bound object
Case acTextBox: astrCtlName(i, 1) = "Text Box"
Case acListBox: astrCtlName(i, 1) = "List box"
Case acComboBox: astrCtlName(i, 1) = "Combo box"
Case acSubform: astrCtlName(i, 1) = "SubForm"
Case acObjectFrame: astrCtlName(i, 1) = "Unbound object frame or
Case acPageBreak: astrCtlName(i, 1) = "Page break"
Case acPage: astrCtlName(i, 1) = "Page"
Case acCustomControl: astrCtlName(i, 1) = "ActiveX (custom)
Case acToggleButton: astrCtlName(i, 1) = "Toggle Button"
Case acTabCtl: astrCtlName(i, 1) = "Tab Control"
End Select
Next i

'Print out the array in an orderly fashion
Debug.Print "Control Name", "Control Type"
Debug.Print "------------", "------------"
For i = 0 To intCnt - 1
Debug.Print astrCtlName(i, 0), astrCtlName(i, 1)
Next i
Erase astrCtlName
End Function
'************ Code End ***************


You pass your form name to his function:

Call fEnumControls("frmfdainput")

Put his code in a module.

You can put your call in the immediate window.

HTH, UpRider

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question