Proper Code Format

  • Thread starter Thread starter Danu
  • Start date Start date
D

Danu

In the past I have been able to make a label associated with a text box
appear on a form if certain values appeared in the text box. See below:

If Me![txtNPA] = "(123)" Then
Me![lbl179].Visible = True
ElseIf Me![txtNPA] = "(456)" Then
Me![lbl179].Visible = True
ElseIf Me![txtNPA] = "(789)" Then
Me![lbl179].Visible = True
Else
Me![lbl179].Visible = False
End If

I still want to use this visible property only this time I need the the
label to appear if the value in the text box is not one of about 22 values.
This would make a VERY long If/ElseIf statement. What is the most efficient
way to do this?

Thank you in advance.
 
In the past I have been able to make a label associated with a text box
appear on a form if certain values appeared in the text box. See below:

If Me![txtNPA] = "(123)" Then
    Me![lbl179].Visible = True
ElseIf Me![txtNPA] = "(456)" Then
    Me![lbl179].Visible = True
ElseIf Me![txtNPA] = "(789)" Then
    Me![lbl179].Visible = True
Else
    Me![lbl179].Visible = False
End If

I still want to use this visible property only this time I need the the
label to appear if the value in the text box is not one of about 22 values.
This would make a VERY long If/ElseIf statement. What is the most efficient
way to do this?

Thank you in advance.

use a select case statement instead

SELECT CASE strText
CASE "A", "B", "C"
'do one thing
CASE "D"
'do another
CASE ELSE
'do the default thing
END SELECT
 
Using the philosophy that all data belongs in tables, I would suggest you
create a table with all the values that would cause the lable to be hidden.
Then it becomes very little code:

Me.SomeLabel.Visible = IsNull(DLookup("[FieldName", "ValueTable",
"[FieldName] = " & Me.txtSomeControl))

Not only does this reduce to a minimum the code required, but if you ever
have to add or delete some of the values, it doesn't require a modificatoin
to your application, just add or delete a row in the table.
 
Back
Top