Form Field Auto Disable

Ivan Howard

Active Member
Joined
Nov 10, 2004
Messages
333
Hi All,

I would really appreciate some help with this issue.

I have a form, fed by one table and tt contains employee information, including a status flag to show if they are currently employed or not.

What I would like to do is when this flag is changed to "Inactive" on a particular record, I would like the rest of the fields on the form to show as disabled/formatted greyed out. Obviously when you move onto another "Active" record, all fields should become enabled again.

Any ideas?

Thanks very much.
Ivan
 

Excel Facts

Return population for a City
If you have a list of cities in A2:A100, use Data, Geography. Then =A2.Population and copy down.
Hi Ivan

You will need to create a VBA event to do this for you, as follows: open the form in design view, right click the status flag indicator > 'Properties' > 'Event' tab > 'On Click' event > click the 3 dots to the side > 'Code Builder' > 'Ok' > this will open the VBA screen and create the beginnings of an 'on click' event for your check box.

Enter code similar to the following :
Code:
Private Sub MyStatusBox_Click()
    If Me.MyStatusBox.Value = -1 Then
        Me.MyField.Enabled = True
        Me.MyField2.Enabled = True
        'etc.
    Else
        Me.MyField.Enabled = False
        Me.MyField2.Enabled = False
        'etc.
    End If
End Sub
I used a check box called 'MyStatusBox' (yours will have a different name) and I was enabling/disabling 2 fields called 'MyField' and 'MyField2' (again your names will differ). Add more lines to suit and you may want to check the logic is the right way around.

The next thing will be getting the form to update itself when you scroll through different records. Once again get into the design view of the form, select menu option 'Edit' > 'Select Form' > menu option 'View' > 'Properties' > 'Event' tab > ''On Current' event (same deal as before to get into the VBA window with the dots etc) > create a procedure like this:
Code:
Private Sub Form_Current()

   Call MyStatusBox_Click

End Sub
This will call the other routine every time you select differing records via the form - this assumes you are only viewing one record at a time. Make sure you use the name of the first routine(as I have).

HTH, Andrew
 
Upvote 0
Hi Andrew,

Thanks very much. This looks like exactly what I need. I will put this in over the weekend.

Have a great weekend.

Take care
Ivan
 
Upvote 0

Forum statistics

Threads
1,214,388
Messages
6,119,229
Members
448,879
Latest member
VanGirl

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top