Loop through controls Ms Access 365 (1 Viewer)

Wysy

Registered User.
Local time
Today, 14:43
Joined
Jul 5, 2015
Messages
333
Thank for all the inputs. I got confused because the VBA editor did not offer those parameters. I am used to use the editor with idea that only those parameters are allowed that show up after typing a dot. Following the recommendations, i got it worked. Thanks for all of you.
 

MajP

You've got your good things, and you've got mine.
Local time
Today, 17:43
Joined
May 21, 2018
Messages
8,463
Thank for all the inputs. I got confused because the VBA editor did not offer those parameters. I am used to use the editor with idea that only those parameters are allowed that show up after typing a dot.
I do not know why, maybe someone here does. But the "Controltype" property has never shown up in intellisense or in the Obect Explorer. MS treats it as an unsupported property but you would think after 20+ years they realize it works.
 

Pat Hartman

Super Moderator
Staff member
Local time
Today, 17:43
Joined
Feb 19, 2002
Messages
42,976
@Wysy does this have something to do with your earlier question? Maybe you should tell us what business problem you are trying to solve instead of just picking a technical solution that you think is correct and asking us to correct the syntax. I've posted a sample that may have nothing to do with your objective but this shows you to use a public function that will work for ANY form. In this case, you put an "R" in the Tag property of any control on any form that you want to mark as required. Then in a form's BeforeUpdate event, you call this function to make sure that all required fields are present.

Code:
Public Function EnsureNotEmpty(frm As Form) As Boolean
Dim ctl As Control

    For Each ctl In frm.Controls
       Select Case ctl.ControlType
            Case acTextBox, acComboBox, acListBox, acCheckBox, acOptionGroup
                If ctl.Tag = "R" Then
                    If ctl & "" = "" Then
                        ctl.SetFocus
                        EnsureNotEmpty = False
                        MsgBox ctl.Name & " is required.", vbOKOnly
                        Exit Function
                    End If
                End If
            Case Else
        End Select
    Next ctl
    
    EnsureNotEmpty = True
End Function
 

Users who are viewing this thread

Top Bottom