Disabling fields

vX987

Registered User.
Local time
Today, 02:24
Joined
Jun 29, 2007
Messages
51
How do I disable all the fields on my form until one of the field has data entered into it? For example,

Field 1 is NOT disable

Field 2
Field 3
Field 4
Field 5

are all disabled until data is entered into Field 1 and then the rest of the Fields AUTOMATICALLY becomes ENABLED.

Can someone help me figure out a code for this?
 
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.
 
Last edited:
You could either use Conditional Formatting or code. The code, in the after update event of field1, would look like:

Code:
If IsNull(Field1) Then
  Me.Field2.Enabled = False
else
  Me.Field2.Enabled = True
End If

You might also want it in the current event to set the controls when you change records.

Edit: sorry RG, yours wasn't there when I started. It's the next step in the evolution as well.
 
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?

THANKS again!
 
NP Paul. Does *everyone* know that Paul is now an MVP? Well deserved my friend.
 
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:

Me!TVRSV.Form!VToeRight.Visible = True
Me!TVRSV.Form!ToeRight.Visible = True

TVRSV is the name of my subform and VToeRight and ToeRight are my controls.
 
You can of course do as you choose, but I personally prefer controls to lock/unlock rather than disappear until needed.
 
RuralGuy,

I wrote a post for you right after pbaldy's post with his code. Can you answer those questions for me?

I am going to mess around with these two suggestions and get back to you.

THANK U, THANK U.
 
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.
 
If you need assistance with what I asked for, then just post back and almost anyone can help.
 
LockControls.... nice routine! Thanks for the post.
 
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.
which code are you talking about?



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!
 
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?
...exactly right and name the module basLocking.
2. Then how and where would I place this module within my database, if I need to at all?
...it is already in the db. No further action is necessary to get it in the db.
3. When setting Tag property to True in each of the controls on my form that I want disabled how would I do this?
...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?
Get to the property sheet for the control and select the Events tab and press the "..." button on the AfterUpdate line.
 

Users who are viewing this thread

Back
Top Bottom