Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

Lock Fields based on selection in combo box

Posted on 2009-02-08
21
Medium Priority
?
783 Views
Last Modified: 2012-05-06
I have a form with 48 text fields and combo boxes.  I need to lock 42 of these if the user selects "Submitted" from a combo box.  Is this possible?
0
Comment
Question by:mato01
  • 11
  • 7
  • 3
21 Comments
 
LVL 75
ID: 23587215
Yes.  The easiest way to do this is:

1) add a tab control on your form with one tab, with the following properties:
BackStyle: Transparent
Style:  None

This will make the tab essentially invisible ... which just your check boxes appearing.

Then ... in the After Update of your combo box:

Private Sub Combo1_AfterUpdate

    Me.YourTabControlName.Locked = (me.combo1 = "Submitted")

End Sub

This is super fast (instant locking) and requires one line of code.

mx
0
 

Author Comment

by:mato01
ID: 23587293
I created the tab and info.  However, I receive the following error on Me.Status

Compile error:
Method or data member not found.

Status is the name of the combo box
TabCtl169 is the name of the


Private Sub Status_AfterUpdate()
 Me.TabCtl169.Locked = (Me.Status = "Submitted")

End Sub
0
 
LVL 75
ID: 23587329
Sorry ... it's enabled:


 Me.TabCtl169.Enabled = (Me.Status = "Submitted")

mx
0
What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

 

Author Comment

by:mato01
ID: 23587404
I changed it; however the fields did not lock.  I have a subform on the Tab control is that correct?
0
 
LVL 75
ID: 23587431
Do you get an error or is that fixed?  If not, then you are saying the check boxes just don't lock ?

You have to be absolutely sure ... that the check boxes are actually on the tab page (tab).  It's easy to fool yourself ... wherein the controls 'look' like they are on the tab, but they are not.

"I have a subform on the Tab control is that correct?"

I don't know.  Where exactly is this line of code:

 Me.TabCtl169.Enabled = (Me.Status = "Submitted")

?
0
 

Author Comment

by:mato01
ID: 23587484

Some of the controls are text boxes, control boxes, and check boxes.  I took the master table and made a subform which I placed on the tab control.  

Then I place the line of code:
Me.TabCtl169.Enabled = (Me.Status = "Submitted") in the After Update of the Status Combo Box.

Are they all suppose to be check boxes for this method to work
0
 
LVL 75
ID: 23587504
"re they all suppose to be check boxes for this method to work"
No no ... any control(s) are fine.

Where is the Combo box? On the main form or the subform on the tab ?

IF .. the combo is on the main form ... and all the controls on the subform, you could just lock/unlock the subform ... and forget the tab.

mx
0
 

Author Comment

by:mato01
ID: 23587543
The combo box is on the main form.
I created a subform and removed all the tabs that I wanted open to get to the 42 controls I want to lock.  
Do I need to place this now on the main form?

I went into details of the subform which I named "lock submit subform".  

Do I place the same code in the After Update of the Combo Box?
0
 
LVL 75
ID: 23587568
On the main form, if you could put the tab control I defined ... with the Controls you want to lock ... and skip the subform altogether ... and keep the combo on the main form ... then the code I posted should work.  Again, you need to be SURE the controls are actually 'on' the tab page.

I need to sign off for an hour or so ... I will be back.

mx
0
 

Author Comment

by:mato01
ID: 23587662
The controls on the tab locks turn grey and are locked,  but the controls on the form do not.
0
 
LVL 75
ID: 23587783
"controls on the form"

??

All controls you want to 'lock' should be on the tab ...

Sorry, not following ...

mx
0
 

Author Comment

by:mato01
ID: 23591992
I think I had missed understood at first.  So here is what I did.  I placed all the controls that I wanted locked on the tab I created on the form and then entered

Me.TabCtl169.Enabled = (Me.Status = "Submitted") in the AfterUpdate properties of the control Status.

Did not work.  
0
 
LVL 75
ID: 23592819
Can you:

1) Compact & Repair (to shrink the size),
2) Zip up the MDB (to further shrink the size)
3) Attach the file for upload here (using the 'Attach File function below) ... removing any sensitive data of course?
4** And please give a clear explanation of exactly how to reproduce the problem.

mx
0
 
LVL 4

Expert Comment

by:klilley
ID: 23595609
To disable the controls on one page of the tab control you should use something like

me.page2.enabled=(me.status<>"Submitted")

where page2 is replaced by the name of the tab controls page that the controls are placed on.  Am i right in saying that if status is not submitted then the controls should be enabled (hence me using not in my example)?

disabling the tab control stops you moving between pages of the control itself ie disabled the buttons
0
 
LVL 75
ID: 23595648
"disabling the tab control stops you moving between pages of the control itself ie disabled the buttons"

In this scheme, which I have been using for year, the only purpose of this tab control with one page (with properties as I specified) is to hold the controls (many) that you want to lock simultaneously - based on some condition, which in this case is:

" I need to lock 42 of these if the user selects "Submitted" from a combo box."
                 ^^^^                    ^^                            ^^^^^^^^^

mx

 
0
 
LVL 4

Accepted Solution

by:
klilley earned 1000 total points
ID: 23595714
ah ok i didnt see that part  about a single page.

I have created an example to explain what i meant have a quick look at form1

test.zip
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 1000 total points
ID: 23595744
Yes ... and note that my tab is basically invisible - all you see is the controls.  Enabling/Disabling is instant - no matter how many controls ... and one line of code.

mx
0
 
LVL 4

Expert Comment

by:klilley
ID: 23595762
I would agree set the tab control as transparent and no buttons tabs etc

In the past i have used a much more complex example utilising the TAG property and looping through the available controls on a form, but this is a much more elegant solution.

Kev
0
 
LVL 75
ID: 23595777
"but this is a much more elegant solution. "

I do have to say ... yes it is.  It's cool, because if you have to lock say 3-4 different sections of controls based on whatever conditions - it's pretty slick.

If you had say 30 controls on a form (or more - kind of extreme) ... using a code loop is sometimes a noticeable momentary performance hit ...

mx
0
 

Author Closing Comment

by:mato01
ID: 31544387
Thanks KEV and MX your combined solution which works perfectly, and is very helpful because I have several areas in which I need to apply this solution.

0
 
LVL 75
ID: 23597167
you are welcome.

mx
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

Sometimes MS breaks things just for fun... In Access 2003, only the maximum allowable SQL string length could cause problems as you built a recordset. Now, when using string data in a WHERE clause, the 'identifier' maximum is 128 characters. So, …
This holiday season, we’re giving away the gift of knowledge—tech knowledge, that is. Keep reading to see what hacks, tips, and trends we have wrapped and waiting for you under the tree.
Learn how to make your own table of contents in Microsoft Word using paragraph styles and the automatic table of contents tool. We'll be using the paragraph styles in Word’s Home toolbar to help you create a table of contents. Type out your initial …
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…

581 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