Disable-based on Adding New Record vs. Editing Existing fields

S

Steve Stad

Is there a way to disable and/or enable the same field(s) based on if a user
is editing an existing record or Adding a new record for a given criteria.
Here is an example for a given field in a matrix for 3 criteria for the same
field.

Edit Adding New Record
Criteria 1 Yes/Enable No/Disable
Criteria 2 Yes/Enable No/Disable
Criteria 3 Yes/Enable Yes/Enable

Let me know if I can provide any more explanation.
Thanks in advance for your assistance.
 
F

fredg

Is there a way to disable and/or enable the same field(s) based on if a user
is editing an existing record or Adding a new record for a given criteria.
Here is an example for a given field in a matrix for 3 criteria for the same
field.

Edit Adding New Record
Criteria 1 Yes/Enable No/Disable
Criteria 2 Yes/Enable No/Disable
Criteria 3 Yes/Enable Yes/Enable

Let me know if I can provide any more explanation.
Thanks in advance for your assistance.

The following will enable or not enable the [First Name] control
depending upon whether or not it is a new record or if the [LastName]
control is a specific value.
Place the following code in the Form's Current event:

If Me.NewRecord Then
Me.[First Name].Enabled = True
ElseIf Me.[LastName] = "Smith" Then
Me.[First Name].Enabled = True
Else
Me.[First Name].Enabled = False
End If

Place the same code din the [LastName] AfterUpdate event.

Change the control names to whatever your actual control names are.
 
S

Steve Stad

Thanks Fred - I tried your code and was able to disable a field but not
Enable it. I have it mixed with this current/existing code to disable fields
- so I may need to remove my current code (since it only accomplishes part of
what I need) and/or add to your If/Else statement.
Current Code
Private Sub EMP_TYPE_AfterUpdate()
EMP_FIRST_NAME.Enabled = (EMP_TYPE = "CTR")
EMPLOYEE_EMAIL_ADDRESS.Enabled = (EMP_TYPE = "CTR")
End Sub
Private Sub EMP_TYPE_GotFocus()
EMP_FIRST_NAME.Enabled = (EMP_TYPE = "CTR")
EMPLOYEE_EMAIL_ADDRESS.Enabled = (EMP_TYPE = "CTR")
End Sub

To explain further - What I am trying to do is....
If New Record AND Emp_type = "M" or "C" then DISable field1.
If it is an existing record and AND Emp_type = "M" or "C" then ENable field1.
If New Record AND Emp_type = "CTR" then ENable field1.
If it is existing record and Emp_type = "CTR" then ENable field1.

I will need to use the code/logic for several fields on one form. I suppose
I can repeat the code for fields 2,3,4, etc. Thanks - I am new to prgramming
- do I need to replace the me. with a form name?

fredg said:
Is there a way to disable and/or enable the same field(s) based on if a user
is editing an existing record or Adding a new record for a given criteria.
Here is an example for a given field in a matrix for 3 criteria for the same
field.

Edit Adding New Record
Criteria 1 Yes/Enable No/Disable
Criteria 2 Yes/Enable No/Disable
Criteria 3 Yes/Enable Yes/Enable

Let me know if I can provide any more explanation.
Thanks in advance for your assistance.

The following will enable or not enable the [First Name] control
depending upon whether or not it is a new record or if the [LastName]
control is a specific value.
Place the following code in the Form's Current event:

If Me.NewRecord Then
Me.[First Name].Enabled = True
ElseIf Me.[LastName] = "Smith" Then
Me.[First Name].Enabled = True
Else
Me.[First Name].Enabled = False
End If

Place the same code din the [LastName] AfterUpdate event.

Change the control names to whatever your actual control names are.

--
Fred
Please respond only to this newsgroup.
I do not reply to personal e-mail
.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top