Solved

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

Posted on 2011-03-07
4
483 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 - Microsoft MVP, Access and Data Platform)
DatabaseMX (Joe Anderson - Microsoft MVP, Access and Data Platform) 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

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

In earlier versions of Windows (XP and before), you could drag a database to the taskbar, where it would appear as a taskbar icon to open that database.  This article shows how to recreate this functionality in Windows 7 through 10.
Access custom database properties are useful for storing miscellaneous bits of information in a format that persists through database closing and reopening.  This article shows how to create and use them.
Familiarize people with the process of utilizing SQL Server views from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Access…
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.

733 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