Solved

problem with a formula to close all controls in a form in microsoft access 2010

Posted on 2011-03-07
4
481 Views
Last Modified: 2012-05-11
my code is


but i get a compile error because vba don't recognize the  "controltype"
If Me.Closed = True Then
    Dim Ctrl As Controls
    For Each Ctrl In Me.Controls
       If Ctrl.ControlType = acTextBox Or Ctrl.ControlType = acCheckBox Or Ctrl.ControlType = acComboBox Or Ctrl.ControlType = acSubform Then
            Ctrl.Locked = True
        End If
    Next Ctrl
Else
    Dim Ctrl As Controls
    For Each Ctrl In Me.Controls
       If Ctrl = acTextBox Or Ctrl.ControlType = acCheckBox Or Ctrl.ControlType = acComboBox Or Ctrl.ControlType = acSubform Then
            Ctrl.Locked = True
        End If
    Next Ctrl
End If

Open in new window

0
Comment
Question by:bill201
  • 2
4 Comments
 
LVL 6

Accepted Solution

by:
JVWC earned 167 total points
ID: 35054651
Not quite sure what you wish to achieve but have you considered using:
Form.Recordlocks ?

Cheers
JC
0
 
LVL 84

Assisted Solution

by:Scott McDaniel (Microsoft Access MVP - EE MVE )
Scott McDaniel (Microsoft Access MVP - EE MVE ) earned 167 total points
ID: 35055194
This line:

Dim Ctrl As Controls

Should be:

Dim Ctrl As Control

(no "s")
0
 
LVL 75

Assisted Solution

by:DatabaseMX (Joe Anderson - Access MVP)
DatabaseMX (Joe Anderson - Access MVP) earned 166 total points
ID: 35059720
Also ... you have this Dim statement twice

Dim Ctrl As Controls

You can only the same variable Dimmed once per Function/Sub.

And in the Else case ... you have:

If Ctrl

which s/b If Ctrl.ControlType

And I suspect for the Else case you meant

Ctrl.Locked = False   ' Instead of True - which is the same as the IF part.

My guess:

    Dim Ctrl As Control
    If Me.Closed = True Then
        For Each Ctrl In Me.Controls
            If Ctrl.ControlType = acTextBox Or Ctrl.ControlType = acCheckBox Or Ctrl.ControlType = acComboBox Or Ctrl.ControlType = acSubform Then
                Ctrl.Locked = True
            End If
        Next Ctrl
    Else
        For Each Ctrl In Me.Controls
            If Ctrl.ControlType = acTextBox Or Ctrl.ControlType = acCheckBox Or Ctrl.ControlType = acComboBox Or Ctrl.ControlType = acSubform Then
                Ctrl.Locked = False
            End If
        Next Ctrl
    End If

mx
0
 
LVL 75
ID: 35059750
And I suspect it can all be shortened to:

    Dim Ctrl As Control

    For Each Ctrl In Me.Controls
        If Ctrl.ControlType = acTextBox Or Ctrl.ControlType = acCheckBox Or Ctrl.ControlType = acComboBox Or Ctrl.ControlType = acSubform Then
            Ctrl.Locked = (Me.Closed = True) ' or (Not Me.Closed = True)
        End If
    Next Ctrl
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
HasData 9 36
Login screen Access Database 8 29
running an update statement after a msgbox (MS Access) 3 28
MS Access 03, TransferText, decimal places 8 37
When you are entering numbers in a speadsheet, and don't remember what 6×7 is, you just type “=6*7" instead. It works in every cell! This is not so in Access. To enter the elusive 42 in a text box, you have to find a calculator, and then copy the re…
Introduction When developing Access applications, often we need to know whether an object exists.  This article presents a quick and reliable routine to determine if an object exists without that object being opened. If you wanted to inspect/ite…
What’s inside an Access Desktop Database. Will look at the basic interface, Navigation Pane (Database Container), Tables, Queries, Forms, Report, Macro’s, and VBA code.
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

914 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now