Here's a hack for doing this kind of thing, but it does takes some doing, and can only be done on a Single View Form (not on a Datasheet or Continuous View Form):
- Delete the Textbox’s attached Label
- Create new Label for Textbox with the Caption of choice (such as Optional Field)
- Set BackStyle and BorderStyle of the Label to Transparent
- Position Label inside of the Textbox
Now, use this code, replacing TargetFieldLabel and TargetField with the actual names of your Controls:
Code:
Private Sub Form_Current()
If Nz(Me.TargetField, "") <> "" Then
TargetFieldLabel.Visible = False
Else
TargetFieldLabel.Visible = True
End If
End Sub
Code:
Private Sub TargetField_GotFocus()
TargetFieldLabel.Visible = False
End Sub
Code:
Private Sub TargetFieldLabel_Click()
TargetField.SetFocus
End Sub
Code:
Private Sub TargetField_LostFocus()
If Nz(Me.TargetField, "") <> "" Then
TargetFieldLabel.Visible = False
Else
TargetFieldLabel.Visible = True
End If
End Sub
I have to tell you, though, if I were doing this, I'd use the BackColor of Controls to denote their optional status, or more likely, to denote the required fields.
Linq ;0)>
The problem with making anything foolproof...is that fools are so darn ingenious!
All posts/responses based on Access 2003/2007