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 setup the for each 
statement.


Thanks
BW 


0
BW
3/11/2008 3:19:09 AM
access.formscoding 7493 articles. 0 followers. Follow

3 Replies
511 Views

Similar Articles

[PageSpeed] 29

Something like this might work;

Dim ctl As Control

For Each ctl in Me.Controls
  If Left(ctl.Name,4) = "txtd" Then
      ctl.Locked = True
  Else
     ctl.Locked = False
  End If
Next ctl
-- 
_________

Sean Bailey


"BW" wrote:

> 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 setup the for each 
> statement.
> 
> 
> Thanks
> BW 
> 
> 
> 
0
Utf
3/11/2008 4:07:00 AM
On Mon, 10 Mar 2008 23:19:09 -0400, "BW" <basic8@hotmail.com> wrote:

>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 setup the for each 
>statement.
>
>
>Thanks
>BW 
>

The Tag property of controls may be handy here. You could have a value in the
tag which indicates that it should be locked, or locked based on the value of
OpenArgs.

in either case, looping through the Controls collection is easy:

Dim ctl as Control
For Each ctl In Me.Controls
  <do something with the control, e.g. check if you want to lock it>
  If <you want to lock it> Then
      ctl.Locked = True
  End If
Next ctl

Just note that this loops through ALL the controls - labels, lines,
rectangles, textboxes, etc. - not just databearing controls.
-- 

             John W. Vinson [MVP]
0
John
3/11/2008 5:25:29 AM
Worked Great....Thanks


BW
"John W. Vinson" <jvinson@STOP_SPAM.WysardOfInfo.com> wrote in message 
news:no5ct3pl5ukmgaacu0qevrsk7502mtapat@4ax.com...
> On Mon, 10 Mar 2008 23:19:09 -0400, "BW" <basic8@hotmail.com> wrote:
>
>>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 setup the for each
>>statement.
>>
>>
>>Thanks
>>BW
>>
>
> The Tag property of controls may be handy here. You could have a value in 
> the
> tag which indicates that it should be locked, or locked based on the value 
> of
> OpenArgs.
>
> in either case, looping through the Controls collection is easy:
>
> Dim ctl as Control
> For Each ctl In Me.Controls
>  <do something with the control, e.g. check if you want to lock it>
>  If <you want to lock it> Then
>      ctl.Locked = True
>  End If
> Next ctl
>
> Just note that this loops through ALL the controls - labels, lines,
> rectangles, textboxes, etc. - not just databearing controls.
> -- 
>
>             John W. Vinson [MVP] 


0
BW
3/13/2008 1:30:39 AM
Reply:

Similar Artilces:

Merging List w/ a Form
Can anyone assist me with merging a form created in Excel with a database (or list) also created in Excel? I know how to merge an Excel worksheet to be used as a database for Word in the Mail Merge command, but my FORM, with which I am trying to merge my database, was created in Excel and needs to remain under its format (not be converted to Word). I am filtering the information I need from the database to be imported to the Excel Form. Any help would be appreciated. Thank-you. If you're trying to display information from one record in the database, there are sample files here...

IE8 Instant search box
Hi All I finally succumbed to the temptation to download IE8. I have spent the last 3/4 of an hour trying to regain control of my browser :-) I have switched off all accelerators and all that other stuff - even figured out how to stop the browser popping up the accelerator icon EVEN though I'd switched them off . . . I am happy to use the instant search box. (It's in a convenient place...). I DO NOT WANT any kind of suggestion from IE8 about what I'm looking for. I KNOW what I'm looking for - and the computer hasn't got a clue . . . So managed to sw...

How to display mfc control in new look style?
Hi, anybody knows how to show mfc controls like button or other controls in new look style? Please see below link to know about what i mean by new look style is. http://www.geocities.com/henky_arektc97/question/ I want to make my controls in dialog shown as Picture 2, not as Picture 1 (look at the button). Are there lack of some defines or codes or something else, because when I create new project again, the dialog will be displayed as I want in Picture 2. I use MFC 9 (vs2008). Thank you for any help! "Saitama" <Saitama@discussions.microsoft.com> wrote in message ne...

Tabbing into continuous subform ignores the first control
When I tab into the subform, from the last position in the main form, the focus moves to the second control in the continuous subform except on the first record entered in a session. I shift+tab back to the first control and the tabbing is normal from then on until the next record gets to the subform. The order of the controls on the subform is the same as the fields in the underlying table and the effect is the same in Datasheet view (of the subform). This first control on the subform is a combo box if that effects anything. Is there a way to get the tabbing right? ern. No, I thought the...

Condition navigating between Controls
I have a form in access 2007, with several controls. I used the On Exit Event Procedure for navigating among controls. Example: If Method of Payment = “Check” Then Check No.Set Focus End If If Method of Payment = “Credit Card” Then Credit Card Name.Set Focus End If End Sub And so on for all controls. Form functioned well for months, however today went wild. Navigation order does not execute Event Procedure it follows exactly the order of TAB ORDER DIALOG BOX. Please advice -- Bardia It sounds like the On Exit event is not firing for some reason. Put these two lines of co...

Filter Report by Form
I'm using the following code from the wonderful Allen Browne which works perfectly in an either or scenario (either by Start/End Date(s) OR filtering by client name; but I don't know what syntax to use to filter by Start/End date(s) AND anything typed in the client name field. I'm sure it's easy but I can't get my head around it. I appreciate any and all assistance!! Private Sub cmdPreview_Click() 'On Error GoTo Err_Handler 'Remove the single quote from start of this line once you have it working. 'Purpose: Filter a report to a date r...

Button on Form to Run Report based on Query with Parameters
Hi Guys. I am busy working on a stock control database (and job control). When I have a Form Open, it shows several fields, including JobID (Which is the PK for that job) (frm_Invoicing) I also have a Query that when Run, it prompts for the JobIDNo. (qry_CustJobsInvStock) I have a report based on that query. (rpt_CustJobsInvStock) I have added a button onto the form (onclick -> DoCmd.OpenReport) to open and automatically print the report, But I just cannot figure out how to get it to get my JobID from the form, and to Automatically add it as a Parameter for the que...

Control Supported Device List for Active Sync
Hi I want to restrict what devices can connect to Active Sync - there is a built in list of supported devices which the service packs keep updating but is there a way to control this list yourself i.e. to only include two devices in the list? I want to control which devices meet the company standard and stop any which don't! More Info: Overview of mobile devices that are supported by Outlook Mobile Access in Exchange Server 2003 http://support.microsoft.com/Default.aspx?kbid=821835 Thanks Clive ...

Center Access2007 Form in the middle of access Main Window
Thank You Is there any easy way to center access 2007 forms in the middle of the screen (Monitor) or access main window. and give me good result Hello, I think there is no built in feature to achieve this goal. You may need to create a new form and configure it as the main window. You could enumerate forms and create buttons etc to open forms from this main form. For example, you could use hte following code enumerate forms in your database: Dim db As Database Set db = CurrentDb Set cntContainer = db.Containers("Forms") For Each doc In cntContainer.Documents Str...

Printout Method
In building a form to allow users to print a "blank form" I've constructed as an Access Report, I'd like the user to be able to select the number of copies to print. It looks like the PrintOut Method would be a good choice for this, but I'm not smart enough to know quite how to get the "Copies" argument to get its input from the textbox on my form, where the user will enter the number of copies they'd like to print. Suggestions? -- Thanks, Croy Does the report have a record source? -- Duane Hookom Microsoft Access MVP If I have helped you, please help...

email form script to show email adresses of all recipients
I see there is a field in the attributes called torecipients but I cannot add it to the email form. Is there a way I can script this into the email form to show the email addresses of all of the recipients. My idea involved creting a new attribute called all_recipients and adding it to the form then doing a onchange for each of the to, cc, and bcc fields to update all_recipients. SO far it doesnt work. All the field returns is "undefined". Any help is greatly appreciated!!! ...

Fill Form And Get $5000 To Your Home.
Fill Form And Get $5000 To Your Home At http://ukcitygirls.co.cc Due to high security risks,i have hidden the cheque link in an image. in that website on left side below search box, click on image and enter your name and address where you want to receive your cheque. please don't tell to anyone. ...

Updated records in forms
Each record in a form is a work order. School, contractor, days of work, etc. I have a pop up calendar to select a week ending date for each record. Record 1's week ending date is Nov 13, 2009. Record 2's week ending date is Nov 20, 2009. When I change the date in record 2, it's changing the date in record 1. Each record's week ending date become all records' week ending date? Can I use a pop up calendar in a record and be able to retain the correct week ending date for each record. If so, how would I be able to accomplish this? Thanks for your inp...

requery subform from sub form
Thank you how can i requery subform from subform ? "a" <youb@hotmail.com> wrote in message news:%23R9c$8tSIHA.2000@TK2MSFTNGP05.phx.gbl... > Thank you > how can i requery subform from subform ? Me.Parent!Subform2ControlName.Form.ReQuery thank you the work correctly "Stuart McCall" <smccall@myunrealbox.com> wrote in message news:fl83eg$3o6$1$8300dec7@news.demon.co.uk... > "a" <youb@hotmail.com> wrote in message > news:%23R9c$8tSIHA.2000@TK2MSFTNGP05.phx.gbl... >> Thank you >> how can i requery subform from subfo...

Controls resize when clicked
In Excel 2002, activeX controls such as command buttons, combo boxes, check boxes and option buttons will display inaccurately until they receive focus. Fonts and symbols used in the control often appear distorted until clicked. For example, with the combobox, the dropdown arrow appears scrunched. With command buttons it looks like the height and width are both increased by 1 when clicked and then the button returns to the wrong size when another control receives the focus. This occurs on multiple machines running Office XP, with and without service packs 1 and 2 installed. The probl...

How to create a static derived class with controls inside it
I want to create a CStatic derived class(eg. CMyStatic), which has some controls inside it. At first I want to add these controls at "CStatic::PreSubclassWindow", but if I want to create the CMyStatic programmically, error will appear. So I'm asking when should I add these controls to my class. Thank you. The way I personally got around this problem was to put my creation function in a Function by itself. override the Create method and the PreSubclassWindow methods. From the Create function set a flag that says it is being created using the create function, rather than be...

Control for nested XML Data
I want to show the content of the xml with a control which allows to show the nodes in a nested way. I don't want to use DataGrid which shows the nodes in a tabular form. Is there any suitable control for me? Thanks. -- My C++ and C# ( Traditional Chinese ) Web Site : www.franzwong.com/Home.php Can you elaborate on your requirements? Is this for a web application or a desktop application? If it is for the web, then one way might be to display the XML in an IFRAME. The XML will appear just as it does when you load up an XML document using IE. You might also bind the XML to a treevi...

HowTo: generate Application using new XP-Controls
Hi, when I generate a new Dialog application with the MFC wizard I get an application that does not show the new XP-Controls although I have checked the "Genrate Manifest" checkbox and the startup code also includes the call to InitCommonControlsEx() (with dwICC = ICC_WIN95_CLASSES | ICC_STANDARD_CLASSES). What is wrong? Why don't I see the control styles of ComCtl32.dll Version 6 ??? (My env: VS2005 SP1, WinXP SP2) Thanks for your help! Regards, hd >when I generate a new Dialog application with the MFC wizard I get an application that does not show the new XP-Controls altho...

changing colour of individual items of control created through CListCtrl
Hello, How can I change the colour of individual items inserted in a area, created by using CListCtrl class.Can somebodyguide me? Thank inadvance -- Sadi ----------------------------------------------------------------------- Sadia's Profile: http://www.msusenet.com/member.php?userid=252 View this thread: http://www.msusenet.com/t-187057967 You have to use a owner draw list control. Here is an example http://www.codeproject.com/listctrl/xlistctrl.asp AliR. "Sadia" <Sadia.1rhwgj@no-mx.msusenet.com> wrote in message news:Sadia.1rhwgj@no-mx.msusenet.com... > > He...

Conditional Formatting In a Datasheet Form
Hi All, I am trying to “Condition Format” a column on my form so it will highlight the individual cell if another cell in the same column has the same value. The form is in Datasheet view and it can not be changed from that due to the way I built the database. I have tried to build the condition format like so, Condition1 “Field Value Is” “equal to” [Column Name] and all it dose is it highlight the cell in the column when I input a record into it, regardless if it is a duplicate or not. Is there a way to accomplish this? Thank you for your time, Cage On Thu, 1 Mar 2007 10:34:06 -...

Date field behavior differs between forms
I have two forms with seemingly identical date fields. In one, if I place my cursor in the middle of it, the first number I type gets put in the far left of the field. In the field on the other form, if I place the cursor in the middle, it starts typing right where I am. Any ideas? I have thoroughly looked through the properties of each field and each form and I cannot find what is causing this behavior. I would love to get both of them to start placing typed characters at the far left instead of where the cursor is. Thanks! Check the Text Alignment property of both controls (not ...

Inventory/Stock Control
Does anyone know of a free, simple inventory control spreadsheet/template. All it needs to do is have a list of items (up to 100) with a stock on hand, transfer in and issue out option. Obviously, the transfer in and issue out out must update the stock on hand and then self zero. Any suggestions? Thanks Mike Microsoft has plenty of templates for documents, worksheets, etc on its web site. Several deal with inventory. "Mike Langensiepen" wrote: > Does anyone know of a free, simple inventory control spreadsheet/template. > All it needs to do is have a list of items...

relative references when copying Sheets containing form controls
I've been given a spreadsheet that I need to take copy various sheets from, the sheets contain form controls, when I copy the sheet to a new workbook, named ranges and so on come across fine, but the references to the input ranges of for example the drop down box controls become hard coded to the original sheet, I don't want this.. Is there anyway to alter the way excel copies so that the references remain relative rather than absoloute???? What did you include in the addresses for those references? I put a listbox from the forms toolbar on a worksheet. If I used a range like: $b$...

Changing color of list control
I am using a CListBox control in my application. I need to change the color of scroll bars and columns. I used SetBkColor function but it changes only the bakgrount text portion and not the scroll bars of the control. Can anyone guide me how to change the color of a scroll bar of a list control. Thanks and Regards Sumit T. Marwal "Sumit T. Marwal" wrote: > I am using a CListBox control in my application. I need to change the color > of scroll bars and columns. I used SetBkColor function but it changes only > the bakgrount text portion and not the scroll bars of the ...

how to build a dynamic form designer
hi, I'm looking for a runtime form designer. Where user can create some forms under some predefined business rules. once the user is done with the designs then all the information should be saved in XML or any such sink but not on client at all , you may say it thin client sort of thing. Once this functionality is achieved then I would need some mechanism to have that saved info in XML or DB to display the very forms in another app. So please if anyone had worked on such thing before or can atleast give some pointers that'll be much appreciated. thanks for your time. On...