Find form object

gblack

Registered User.
Local time
Today, 09:46
Joined
Sep 18, 2002
Messages
632
I inherited an Access app, where the previous developer would hide objects underneath other objects or make them so tiny that it makes them nearly impossible to find in design mode. I find myself lassoing everything in hopes I see it's outline... or trying to tab through all the objects.

The code reference and object in the form that I cannot find... there's like a gazillion text boxes dropdown boxes, buttons...ect... so it really is tough for me to look through it all.

Is there a simple way to highlight a form object if you know the name? Or does anyone know how to directly go to the form object from the VBA code, maybe?

Thanks,
-Gary
 
VBA code to do this is very simple.
Code:
Function FindControl(FormName As String, ControlName As String) As Control
    Dim frm As Access.Form
    Dim ctrl As Access.Control
    
    DoCmd.Close acForm, FormName        'make sure form is closed
    DoCmd.OpenForm FormName, acDesign   'open it in design view
    
    Set frm = Forms(FormName)           'set object reference to form
    For Each ctrl In frm.Controls       'enumerate controls
        If ctrl.Name = ControlName Then 'check if we've found it
            ctrl.Selected = True        'if so, selected it
            Set FindControl = ctrl      'assign to function
            Exit For                    'stop looking
        End If
    Next
End Function
 
This row . . .
Code:
ctrl.Selected = True
. . . should be amended to . . .
Code:
ctrl.InSelection = True
 

Users who are viewing this thread

Back
Top Bottom