Conditional Formatting

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I am creating a form where I want to conditionally format one control based
on another control. The first control is a Yes or No question, and the other
is a "If yes, then give the date". I want the second control to be disabled
by default, unless the first control is "Yes". I am not sure if i can do
this thru a wizard, or if I have to write a code for this. Any suggestions
would be greatly appreciated!
 
AccessNovice said:
I am creating a form where I want to conditionally format one control based
on another control. The first control is a Yes or No question, and the other
is a "If yes, then give the date". I want the second control to be disabled
by default, unless the first control is "Yes". I am not sure if i can do
this thru a wizard, or if I have to write a code for this. Any suggestions
would be greatly appreciated!
Exactly the same question from me.
Some VBcode has once been posted to perform the task. This code however was
nearly 2 pages long, and included several unclarities.

It should be much more simple than that, shouldn't it?
Anyone?
 
Not that hard. If you want the second control to be disabled by default, set
it's Enabled property to No in design view. Then in the After Update event
of the first control, a Check Box, all you need is this to enable it and
populate it with the current date:

If Me.FirstControlName = True Then
Me.SecondControlName.Enabled = True
Me.SecondControlName = Date()
Else
Me.SecondControlName.Enabled = False
End If

Now, as you navigate through the records in your table, this can change
based on the field your controls are bound to, so you will need the following
in the Form's Current event to keep these controls in sync with the current
record:

If Me.NewRecord Then
Me.FirstControlName = False
Me.SecondControlName.Enabled = False
Else
'Here is gets fuzzy, because I don't know what your business rules are. It
will depend on whether you only want to allow the date to be entered for new
records or not and whether your first control is bound to a field in the
table. If you need more assistance, post back with the business rules.

If Me.FirstControl = True Then
Me.SecondControl.Enabled = True
 
If you are using Access 2000 or greater, you should be able to do this using
the conditional formatting. This assumes that you have the yes or no
question and the If Yes, give date field in the same record.

In design view, click on the field you want to enable/disable
Select Conditional formatting from the Format menu
Change Condition 1 from "Field value is" to "Expression is"
In the box that appears enter criteria YesNoField = False
Click the Enabled button (last button in row of icons) so it disables the
control
Click OK

Test that and see if it 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

Back
Top