Set Enabled On All Controls in a Form?

I am trying to set all controls visible, unlocked, and enabled, as the
baseline for disabling or locking down some fields based on other
criteria. Here's what I tried, which gives me an "Invalid or
unqualified reference" error:

   Function SetEnabledFieldsBase()
       Dim ctl As Control
       For Each ctl In Me.Controls
           .Enabled = True
           .Visible = True
           .Locked = False
       Next ctl
   End Function

I based this on several examples that were intended to do something to
all text boxes on a form. (I have never done this before, so sorry if
this is just really bad syntax.)

Thanks!

0
HumanJHawkins
10/11/2007 8:11:44 PM
access.formscoding 7493 articles. 0 followers. Follow

3 Replies
1166 Views

Similar Articles

[PageSpeed] 19

HumanJHawkins wrote:

>I am trying to set all controls visible, unlocked, and enabled, as the
>baseline for disabling or locking down some fields based on other
>criteria. Here's what I tried, which gives me an "Invalid or
>unqualified reference" error:
>
>   Function SetEnabledFieldsBase()
>       Dim ctl As Control
>       For Each ctl In Me.Controls
>           .Enabled = True
>           .Visible = True
>           .Locked = False
>       Next ctl
>   End Function
>
>I based this on several examples that were intended to do something to
>all text boxes on a form. (I have never done this before, so sorry if
>this is just really bad syntax.)


That vode is nice.  One thing though, not all controls have
all those properties (e.g. labels) so you need some error
handling to deal with those situations.  In a procedure this
simple, I think just adding:
	On Error ResumeNext
before the For statement would be sufficient.

It would be better if you could arrange things to avoid this
kind of blanket preperty settings.  One way is to use the
Tag property of each control you want to set or reset.  E.g.
if the controls you want to disable have D in their Tag
property, then you could modify the procedure to disable
them in the same loop.

   Function SetResetControls(grp As String)
       Dim ctl As Control
		 Dim OnOff As Boolean
		 On Error ResumeNext
       For Each ctl In Me.Controls
				OnOff = (ctl.Tag = grp)
           .Enabled = OnOff
           .Visible = OnOff
           .Locked = Not OnOff
       Next ctl
   End Function

You can then have several different groups of controls to
enable/disable just be using a different tag.  Using Like
and wildcards instead of =  you could eve have overlapping
groups.

Note that if your form has a lot of controls, it would be
faster to use the form's load event to populate a collection
with the controls you want to manipulate.  This way the
procedure won't waste time with controls that are never
set/reset.

-- 
Marsh
MVP [MS Access]
0
Marshall
10/12/2007 4:37:36 AM
Marsh's suggestion about using the Tag Properties to selectively manipulate
control properties is bang on! The Tag Property is propbably one of the least
known/most under utilized ones out there, and it can be powerful!

If you know what kind of controls you want to manipulate, you can also
stipulate that in your code, like the following, which includes the most
common controls:

Dim ctr As Control
For Each ctr in Me.Controls
   Select Case ctr.ControlType
     Case acTextBox, acComboBox,acCommandButton, acLabel, acListBox,acTabCtl
       'Do your thing here
   End Select
Next

Obviously you can include in Line #4 of the code only those type of controls
you want to deal with.

-- 
There's ALWAYS more than one way to skin a cat!

Answers/posts based on Access 2000

Message posted via AccessMonster.com
http://www.accessmonster.com/Uwe/Forums.aspx/access-formscoding/200710/1

0
Linq
10/12/2007 12:32:06 PM
Thanks to both of you for two good solutions. I used the Select/Case
suggestion and it works beautifully.

0
HumanJHawkins
10/12/2007 7:06:27 PM
Reply:

Similar Artilces:

Autofill In Linked Forms
I have created a couple of forms by selecting all the fileds in the form wizard from two tables: 1. Suppliers (Fields: Supplier, Address, Contact, etc.) 2. Products (Fields: Supplier <Lookedup from Supplier Table>, Product, Rate, etc.) Upon clicking the toggle button on Suppliers form I have the Products form opened. However, as I enter the data in it, I want the Supplier filed in the same be automatically be filled with the Supplier name as in the opened Supplier form so as to be filtered and displayed the next time I open the same instead of manually inserting the sa...

Mail Enabled : How to retrieve the mails.
Hi, I have created one mail enabled account with smtp address but how do I retrieve the mails ? Thank you. Rgrds, Zul On Wed, 18 Jan 2006 15:00:36 +0800, "Zul J" <mlist@istar.com.my> wrote: >Hi, > >I have created one mail enabled account with smtp address but how do I >retrieve the mails ? > >Thank you. > >Rgrds, >Zul > A mail enabled account doesn't have a mailbox. When you create that account you specify an external SMTP address and collect the mail from there however you would normally do it. Hi Mark, This means that the exchang...

Control "Reply to all" for dl's.
We have a global distribution list that only one user will have access to. How do we stop someone from replying to all when they receive a message from that dl? thanks On Thu, 12 May 2005 12:36:06 -0700, "MJKQB" <MJKQB@discussions.microsoft.com> wrote: >We have a global distribution list that only one user will have access to. >How do we stop someone from replying to all when they receive a message from >that dl? > >thanks Exchange General tab/ Message Restrictions and add the users who can send to that DL. ...

Name Range with using Data Form
I first created a variable with A1:D1, four columns with named variable Data. How to expand this Data range to A1:D2 after using the DataForm to add one row data in the worksheet?? The same, the Data range should be A1:D3 when adding one more data row... million thanks Hi use the following formula in the name definition dialog =OFFSET($A$1:$D$1,0,0,COUNTA($A:$A)) >-----Original Message----- >I first created a variable with A1:D1, four columns with named variable >Data. How to expand this Data range to A1:D2 after using the DataForm to add >one row data in the worksheet?? The...

Can see form in design view but not in open or layout view
I have set up the tables, relationships and forms. When I first created the form I was able to view when clicking open. I made a couple of changes and now when I click on open a box pops up to enter perimeter value. Also, I can no longer see the form in opne or layout but if I click for design view, I can see my form and all the tabs. There is either something missing or somthing is named incorrectly. Had a similar problem recently where a new version was installed in the front end, but the table in the back end had not been updated properly (a new field) and the new version of the...

The Settings button keeps disappearing
Hi, I'm having a weird problem when I access CRM using the web client. When I access the site, I see all the buttons (Workplace, Sales, etc) except the Settings button. If I reboot, the button is back. My security role is system Admin. Any idea what is wrong? Thanks! Simon Are you running the Microsoft CRM Outlook Desktop client in parallel? Frank Lee, Microsoft CRM MVP Workopia, Inc. http://microsoft-crm.spaces.live.com "Simon Renshaw" wrote: > Hi, > > I'm having a weird problem when I access CRM using the web client. When I > access the site, I s...

Setting .doc default to .doc, not .dox
Version: 2008 Operating System: Mac OS X 10.5 (Leopard) Processor: intel How do i do this for all new documents? > How do i do this for all new documents? I meant .doc instead of .docx Word> Preferences> Save, choose Word 97-2004 Document (.doc) from the Save Word files as: list - just keep in mind that you'll be constantly working in Compatibility Mode which will prevent the use of some of 2008's features. HTH |:>) Bob Jones [MVP] Office:Mac On 4/23/08 7:50 PM, in article ee99690.-1@webcrossing.caR9absDaxw, "dbdbdb@officeformac.com" <dbdbdb@officeform...

Public Folders: How to set up Auto-Reply in EX2003?
Hi guys, I've configured a public folder to receive mail from the Internet, and also set up an auto-reply rule using the Folder Assistant to reply when an e-mail is sent to the folder. The folder will auto-reply just fine if I e-mail it from within the Exchange organization, but if folks from the Internet e-mail the folder, it doesn't reply. Any ideas? Thanks! Jeff I ended up figuring out what the problem was. Just in case anyone else has this problem, what I needed to do to fix it was: - Open Exchange System Manager > Global Settings > Internet Message Formats - Right-c...

Subtracting value from main form
I have a borrow module which will alow user to return item separately. So, I have get the structure of returning it separately. In my main form is the borrowing item, with the loaned quantity and the owed quantity (will be calculated). In the subform, there is the returning transaction. User will need to key in the quantity returned and it will be automatically deducted from the quantity owed. But how am I supposed to get the quantity deducted while it 1 is in main form and the other is in subform? -- Message posted via AccessMonster.com http://www.accessmonster.com/Uwe/Forums.aspx/access-fo...

Setting directory for file save in macro
Hi Thanks to a generous poster I now have a great bit of code to use in a macro for Excel which saves a text file (I'm no VBA programmer so this was really helpful), i.e.: Open "Test.txt" For Output As #1 (rest of code) My problem now is this: The macro saves test.txt to Excel's current active folder, rather than the folder that the current workbook is contained in. For example, if I last saved an Excel workbook to c:\workbooks\, and the workbook that I have open exists in c:\workbooks\workbook1\, when I run the macro it saves the text file in c:\workbooks\. If I ...

Outlook/Access 2003
I've been doing a lot of research and purchased (but haven't completely read) Sue Mosher's book. However, before I spend much more time I'd like to find out if my idea is even feasible. The basic idea is to create an appointment system for multiple therapists that can be used by a receptionist and other staff. Using Outlook and Exchange is very nice but the appointment data needs to end up in an Access table immediately. We can purchase SBS 2003 with Exchange 2003 or we can buy a third party tool for calendar sharing whichever would be the easiest to use. I currently...

Keeping forms in order they are entered?
I am working with a database that was designed for us and have pretty much just used without having to change much in but have now run into a problem and hope someone can help. We track and number complaints we recieve by number using last digits of year recieved then next number, i.e. a complaint recived 12/31/09 might be 9234 and first one received this year would be 10001 and the next would be 10002. The problem is now when I open my forms and go to the last one it is the 9234 instead of the 10002 which I need. How do I keep that last form I entered last the next time I open the data...

Trying to set up account, geting nowhere FAST!
From: "Lenora" <lmandre@windstream.net> Subject: Understanding what Microsoft Communities Date: Friday, September 14, 2007 5:41 PM Hello out there! What is Microsoft Communities all about? Is it something that comes with no charge when you get Microsoft Vista? This is the 4th computer I've had (besides ones at work). First a Compaq that I loaded everything I could from work, the computer guy gave me stuff...did work at home, brought it back to work, and visa versa. Second was a re-built computer that was given to me by a man in the town we had moved to...out of the g...

Printing
Hope you folks can help me out with a strange one. I have several worksheets formatted in exactly the same way as follows: Col A - width 4 Col B - hidden Col C - width 4 Col D - Width 108 Col E - Width 3 Col F - Width 11 Col G - Hidden Col H - Width 11 & Empty My print range should be Cols A:G (I have used page setup to set the scaling to fit 1 page wide by [blank] pages tall, thus each sheet will print as many pages as required depending on number of rows] When I have the print range set to A:G only columns A:E show on the print preview (and also on the actual print out) and when I m...

active X control
I have a calandar (active x control) on my form. Does anyone know how to link/sync it to a bound control; i.e., when a user chooses a date control, the calandar appears, and when a date is selected it populates into the requisite field. alex Try this: http://www.datastrat.com/Download/XCalendar2K.zip -- Arvin Meyer, MCP, MVP http://www.datastrat.com http://www.mvps.org/access http://www.accessmvp.com "alex" <sql_aid@yahoo.com> wrote in message news:1182963470.109302.283780@q75g2000hsh.googlegroups.com... >I have a calandar (active x control) on my form. > Does anyo...

increment through controls on form
I have a form that I've name the controls on it in such a way that I could determine through open args if it should be locked or not. Example any text box that begins with txtd would be unlocked with open args of 1. I was hoping there was a way I could just move through the controls in a loop and set that property with one function.....I'm not for sure how to accomplish this though. Does anyone have some sample code on how to "loop" through all the controls on a form and set the locked property? I can write the criteria portion if I could get a sample of how to ...

Attach Trigger to Save Function of Form
I am in the processes of trying to attach a trigger to the Save function of an already existing GP form using Dex. In one of the documents, it states that the CM_Checkbook_Maitenance has a SaveRecord function. I am trying to acces the function that is similar to this on the PM_Vendor_Maitenance form. I tried using SaveRecord and when I tried to compile it it says that it is an unknown reference. Is there some documentation with a list of the functions for each form? Mike, PM_Vendor_Maintenance is an older form and probably doesn't have a SaveRecord function. Try running t...

look way to map form at CRM frontend to tables at CRM database
How can I find out what tables which new record has been added on when I enter data through a form in CRM front end? I try to find way to map form in the CRM frontend to the tables at the CRM database at backend? It is CRM 3.0 Thank in advances for help! ...

Unable to delete the Dead Domain controller
Dear, Iam working on windows server 2008 Ent Ed I have two doman controllers in the domain both are GC but only one domain controller has all the fsmo roles but iam having replicattion problems with the dead DC (i.e mppkw-database) and Iam unable to delete or remove the dead domain controller from the domain and iam having follwing problems using the ntdsutil :- matadata cleanup select operation target: list domains Found 1 domain(s) 0 - DC=mediaphoneplus,DC=com select operation target: select domain 0 No current site Domain - DC=mediaphoneplus,DC=com No current server N...

Exchange error
Hello, for one week now, my exchange 2000 server crashes nearly every night at random time, the only solution to have it all restart is to restart the entire server. In the application log, multiple error events are reported like these : Event Type: Error Event Source: Userenv Event Category: None Event ID: 1000 Date: 26/07/2005 Time: 01:27:39 User: NT AUTHORITY\SYSTEM Computer: BELLINI Description: Windows cannot establish a connection to *domain name* with (1364). Event Type: Error Event Source: Userenv Event Category: None Event ID: 1000 Date: 26/07/2005 Time: 01:37:41 User: ...

More control over taxation
I would like to be able to exempt items for different levels of taxation while still using "tax by customer." Rather than taxable or non-taxable, I need to be able to exempt from federal and state separately. Thanks, dan@endurosport.com ---------------- This post is a suggestion for Microsoft, and Microsoft responds to the suggestions with the most votes. To vote for this suggestion, click the "I Agree" button in the message pane. If you do not see the button, follow this link to open the suggestion in the Microsoft Web-based Newsreader and then click "I Agree...

upload form problem / server question
www.icingpictures.co.uk / win xp / frontpage 2003 Want to create a form with upload file form field - i read on this forum that the server type i use is important - it should be a windows type server with frontpage extensions - i currently use a linux server with front page extensions - do i need to change to a windows server? Thanks for taking a looka t my question. Joyce Yes, you must have a Windows Server, just like you stated you read. -- Tom [Pepper] Willett Microsoft MVP - FrontPage Since 1997 --------------------------- "threademporium" <threademporiu...

Setting up Exchange 2003
I had this problem the other day while extending the schema in preparation for an upgrade to Exchange 2003. I searched through a lot of databases and search engines, and found that a lot of people have had this problem, but none of the forums led to a clear cut answer to the issue. So, I thought I'd share my solution to try and help others out, and save them some time and frustration. I was ready to call Microsoft support right before I figured this out. While running forest prep (setup /forestprep), setup failed with Error code 0XC103798A. It then specified to check the Exchange inst...

Tab control + having same size for all tabs
Hello All I am working on tab control in which I want to set the same size of all tabs of tab control. I am adding the tabs dynamically . When I saw the .NET style tab control ( Look tab control used in MSDN) , I felt that it is more elegant than the old looked MFC tab control. My ultimate goal is to have the same size for all tabs irrespective of text it has ( MFC's default behaviour shows the full text in tab ) If the text exceeds that width, then It will make it shortened by adding .... ( three dots ) (e.g. "The text of tab...Will Come here" ) , I know that I will have to wri...

Is batch ID is required in payables transaction entry form?
Is batch ID is required in payables transaction entry form? How about if I just have 1 invoice and do not want to create a batch for it? can I still process the invoice? Hi Bab, A batch i.d. number is not required. You have to post your invoice both in the Payables module and also in the Financial module. I check weekly for any "series batches" that have not been posted in my A/P, A/R, P/R, and Financial modules. If they go unposted it can create havoc. I hope this has been helpful to you. -- Diana "Bab" wrote: > Is batch ID is required in payables transa...