Link to home
Start Free TrialLog in
Avatar of mato01
mato01Flag for United States of America

asked on

Lock Fields based on selection in combo box

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?
Avatar of DatabaseMX (Joe Anderson - Former Microsoft Access MVP)
DatabaseMX (Joe Anderson - Former Microsoft Access MVP)
Flag of United States of America image

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
Avatar of mato01

ASKER

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
Sorry ... it's enabled:


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

mx
Avatar of mato01

ASKER

I changed it; however the fields did not lock.  I have a subform on the Tab control is that correct?
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")

?
Avatar of mato01

ASKER


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
"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
Avatar of mato01

ASKER

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?
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
Avatar of mato01

ASKER

The controls on the tab locks turn grey and are locked,  but the controls on the form do not.
"controls on the form"

??

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

Sorry, not following ...

mx
Avatar of mato01

ASKER

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.  
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
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
"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

 
ASKER CERTIFIED SOLUTION
Avatar of klilley
klilley
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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
"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
Avatar of mato01

ASKER

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.