If Then

J

Jim

I have a form where I need a Yes/No field to dictate which of the two
following fields have focus.

If field 123 is yes then field abc is enabled and xyz is disabled If field
123 is no, then abd is disabled and xyz is enabled.

Is this type of thing possible?
 
G

George Nicholson

In the Form_Current event and the ctl123_AfterUpdate event.

"ctl" refers to whatever control you are using for the respective fields.
Controls are enabled/disabled, not Fields.

ctlABC.Enabled = ctl123
ctlXYZ.Enabled = Not ctl123
 
J

Jim

Sorry to be a bother, but in the Enabled Property Setting I can only select
Yes or No, and not input what you suggested. Please advise.
 
B

Beetle

Jim;

The method George is referring to needs to be done in code. Open the
property sheet for your form, go to the Events tab, and find the
On Current event. Click the elipse to the right of this line and then select
Code Builder. This will open the VB code window, and the following lines
will already be created for you;

Private Sub Form_Current()

End Sub

In between these lines put the code that George suggested, using your
actual control names. Repeat this process for your checkbox control,
but this time use the After Update event.
 
J

Jim

Beetle,

Here is the code I have entered per your instructions:

ctlReason_Enforced.Enabled = Ctl90_Day_Rule_Enforced
ctlGood_Cause_Reason.Enabled = NotCtl90_Day_Rule_Enforced

90 Day Rule Enforced is the Check Box, Reason Enforced is the if Yes and
Good Cause Reason is the If No controls

When I open the form I get a Error 424.

can you advise?
 
B

Beetle

Again, you need to use your exact control names. In the example provided
the "ctl" in front of the control name is just an example of what a
control name *might* look like if you were using naming conventions, which
you are not. Here is another example of how it should look.

The code in the On Current event of your form should look something like;

Private Sub Form_Current()

Me![Reason Enforced].Enabled = Me![90 Day Rule Enforced]
Me![Good Cause Reason].Enabled = Not Me![90 Day Rule Enforced]

End Sub

The code in the After Update event of your checkbox should be;

Private Sub 90_Day_Rule_Enforced_AfterUpdate()

Me![Reason Enforced].Enabled = Me![90 Day Rule Enforced]
Me![Good Cause Reason].Enabled = Not Me![90 Day Rule Enforced]

End Sub

In the above example, “Me!†is not part of the control name. It is an easy way
of telling VBA that the control you are referring to is located on the same
form
that the code is in. Also, I have enclosed your control names in brackets
because
they contain spaces. Enclosing them in brackets is a way of ensuring that VBA
knows they are form controls and not something else.

BTW – you could probably just copy and paste the above code samples and
be done with it, but If you are going to be creating / modifying objects in
this
or other Access applications on a regular basis, I would suggest you start
learning
the VBA side. It will give much greater control over how your app works.
 

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