Iterate through controls for MS Access Forms

73

By msaccessmemento

Example 1: iterate through one form's controls

Private Sub Form_Load()

For Each ctl In Me.Controls

If ctl.ControlType = acLabel Then

On Error Resume Next

ctl.Caption = DLookup("LABEL_USER_COURT", "MAPPING_TABLE", "[LABELS_DB]=" & "'" & ctl.Caption & "'")

End If

Next

End Sub

Example 2: Iterate through all opened forms controls

'**************************************

' Name: Access - update form controls

' Description:This code snippet itterate

' s over open forms in an Access DB allowi

' ng you to easily set properties of contr

' ols programmatically.

' By: RegX

'

' Assumes:This only iterates through ope

' n forms. To use this simply open all the

' forms you want to edit, paste this code

' into a module, and call it from the imme

' diate window.

Possible uses are:

Change any Property of a certain Type of control

Rename controls

'

Public Sub editallopenforms()

'111 = combo

'109 = textbox

On Error Resume Next

Dim frm As Form

For Each frm In Application.Forms

Debug.Print frm.NAME

For Each ctl In frm.Controls

'Debug.Print ctl.NAME & "-"; ctl.Control

' Source & "-" & ctl.ControlType

If ctl.ControlType = 111 Then

'ctl.AllowAutoCorrect = False

End If

Next ctl

Next frm

End Sub

Comments

No comments yet.

Submit a Comment
Members and Guests

Sign in or sign up and post using a hubpages account.



    • No HTML is allowed in comments, but URLs will be hyperlinked
    • Comments are not for promoting your Hubs or other sites

    Please wait working