OnOpen > Field Visible (or not)

  • Thread starter Thread starter Tom
  • Start date Start date
T

Tom

I need a bit of help with a small function.

I need to create a dependency (field visible or not)
between 2 fields (both reside on a tab)

FIELDS:
1. TaskerRequired (Yes/No data type)
2. TaskerNumber (Text data type)


I included the IF/THEN/ELSE function into the OnOpen event
of the FORM (below):

&&&&&&&&&&&&&&&&&

If (Me.TaskerRequired) = False Then
Me.TaskerNumber.Visible = False
Me.TaskerNumberLabel.Visible = False
Else
Me.TaskerNumber.Visible = True
Me.TaskerNumberLabel.Visible = True
End If

&&&&&&&&&&&&&&&&&

Some records may have the TaskerRequired field checkmarked
while others do not have a checkmark. If a TaskerRequired
checkbox is checked for a specific record, then I do want
to show the TaskerNumber field (and its label).

If the record does NOT have a check in the TaskerRequired
checkbox, then I do NOT want to show the TaskerNumber
field (and its label).

Currently, however, I either do show or don't show the
field + plus label (REGARDLESS OF THE ACTUAL VALUE/CHECK
FOR EACH RECORD).

Does anyone know how to fix this?

Thanks in advance,
Tom
 
Use the Current event of the form instead of the Open event.

If the label is attached, there is no need to hide it. All you need is:
Me.TaskterNumber.Visible = Me.TaskerRequired
 
Allen:

This works fabulous!

Please allow me to ask one follow-up question though:

If I "uncheck" a "checked" field (and there was a value in
the TaskerNumber field), how can I reset (delete) the
TaskerNumber field back to a blank value.

Just in case, this does not make sense:

Steps:
1. Open form
2. Checkbox is visible but text field is not
3. Click on checkbox... which makes text field now visible
4. Enter data into text field.
5. ....
6. ....
7. Uncheck checkbox... in turn, the text field should be
emptied out

Current Problem:
The text field is not being emptied at this time. If I
were to check the checkbox again, I still see the "old"
value.

Below is function that hides/unhides the textbox... but it
won't update the textfield.

Private Sub TaskerFlag_AfterUpdate()
Me.TaskerNumber.Visible = Me.TaskerFlag

strSQL = "UPDATE tblCorrespondence SET
tblCorrespondence.TaskerNumber = Null"
CurrentDb().Execute strSQL, dbFailOnError
End Sub


Do you have any suggestions as to how I should update the
textfield after "unchecking" it?


Thanks!

Tom
 
If your form is bound to the table or to an updateable query just use.

Me.TaskerNumber = Null

As a side note, the reason your code wasn't working earlier is that you were
checking a Yes/No field for True/False. You'll get unexpected results most
of the time. You should check for YES or NO.

Kelvin
 
Put the same line into the AfterUpdate event procedure of TaskerRequired.

In case the user undoes the form, you may also want to put this line into
the Undo event of the form:
Me.TaskterNumber.Visible = Me.TaskerRequired.OldValue
 
Kelvin:

Thanks for the info... this works great!

BTW, I am now curious about the Yes/No vs. True/False. I
have seen that the Y/N field stores a Yes as "True" and a
No as "False" when a populated Y/N field changes
from "Yes/No" to a text data type.

For instance, when you copy/paste the structure of a
table, in many instances the data type changes and makes
the checkbox field a textbox.

But who knows... maybe I'm getting something mixed up
here.

Anyhow, thanks again for the feedback.

Tom
 
Allen:

Thanks! This works too... I tested your suggestion
after Kevin's feedback. Both work great!

Tom
 
Back
Top