The following two subs should be put in a standard module.
Code:
Public Sub LockControls()
Dim MyForm As Form
Dim ctl As Control
Set MyForm = Screen.ActiveForm
' Disable each control on the form that has the Tag property set to True.
For Each ctl In MyForm.Controls
If ctl.Tag = True Then
ctl.Enabled = False
End If
Next ctl
End Sub
Public Sub UnLockControls()
Dim MyForm As Form
Dim ctl As Control
Set MyForm = Screen.ActiveForm
' Enable each control on the form that has the Tag property set to True.
For Each ctl In MyForm.Controls
If ctl.Tag = True Then
ctl.Enabled = True
End If
Next ctl
End Sub
Then set the Tag property to True in each of the controls on your form that you want disabled. Then in the Current event of the form test the validity of the trigger control and if you need to disable the controls then Call LockControls. In the AfterUpdate event of the trigger control, assuming you did your validity check in the BeforeUpdate event, Call UnLockControl if your trigger control is properly completed. Post back if you need additional assistance.
Is there anyway you can bold or change the color of the text in your code that I should change to match my database? For example, where it says MyForm, does the name of my form go there?
and also, I'm not too sure on what this means.
"Then in the Current event of the form test the validity of the trigger control and if you need to disable the controls then Call LockControls. In the AfterUpdate event of the trigger control, assuming you did your validity check in the BeforeUpdate event, Call UnLockControl if your trigger control is properly completed."
I apologize on my limited code word understanding. Could you explain this in elementry level?
pbaldy, Your idea might be a little easier for someone of my LIMITED access skills. If I wanted to make some of the controls in a subform disabled also... how would I do that? I've tried:
I believe this is the same form I helped you with before when we were using the Exit event. I've been waiting for you to post back because it was not a particularly good approach to the problem and has unwanted side effects. How about posting your code that is in three events. Current Event of the form, BeforeUpdate event and AfterUpdate event of the date control that is the trigger control. Be sure and put the {code}{/code} tags aroung the code so it is easier to read. Use [brackets] instead of {braces} though.
RuralGuy, I've been away, sorry for not replying any sooner. when you said..
How about posting your code that is in three events. Current Event of the form, BeforeUpdate event and AfterUpdate event of the date control that is the trigger control.
If you think lock controls is my best option right now and fits what I was looking for, then can you please provide me with further assistant?
For your lock controls code, i was wondering if you could provide a step by step explanation of how I would do this and how where I would put the code?
For example, if you were to explain to me how to put a certain control on a click button you'd explain it like
1. create the control using the Toolbox
2. Open properties of the button
3. go to Events, under On Click ... click on the ... then click on Code Builder
4. Place this code between this:
Code:
Private Sub Option6_Click()
[COLOR="SeaGreen"]Place your code here[/COLOR]
End Sub
My questions for your Lockcontrols code are:
1. So I would click 'Module' on the Access window and then click New and place the code you provided for me on the screen? then press save?
2. Then how and where would I place this module within my database, if I need to at all?
3. When setting Tag property to True in each of the controls on my form that I want disabled how would I do this?
4.
Code:
Then in the Current event of the form test the validity of the trigger
control and if you need to disable the controls then Call LockControls.
how would I do this?
5.
Code:
In the AfterUpdate event of the trigger control, assuming you did
your validity check in the BeforeUpdate event, Call UnLockControl if your
trigger control is properly completed.
and how would I do this?
I apologize for my limited code understanding. I hope you can help me out again, thanks!
...by going to the "Other" tab of the property sheet for each control you want locked and typing True in the Tag property at the bottom of that page. You can hold down the shift key while selecting all of the controls then you can set *all* of the tag properties at the same time.
4. Then in the Current event of the form test the validity of the trigger control and if you need to disable the controls then Call LockControls. How would I do this?
...Start by putting Call LockControls in the Current Event of the form. Get to the property sheet for the form and select the Events tab then press the "..." button on the OnCurrent line.
5. In the AfterUpdate event of the trigger control, assuming you did
your validity check in the BeforeUpdate event, Call UnLockControl if your
trigger control is properly completed.
And how would I do this?