I want to put in a default entry in a Yes/No data type field in a table that automatically defaults to a 'Yes' if the criteria is "JT" but leaves it at "0" (empty) otherwise. Any ideas?
You must design a Form for the Table. On the Form VBA Module we can write a small Sub-routine to validate the criteria field value and set the yes/no field's value accordingly.
Immediately after entering the CriteriaField Value as "TJ" or "XY" the following routine can run on the CriteriaField_LostFocus() Event Procedure to validate the user entry and set the yes/no field value:
Sample Code:
Code:
Private Sub CriteriaField_LostFocus()
If Me![CriteriaField] = "TJ" Then
Me![YesNo] = True
Else
Me![YesNo] = False
End if
End Sub
The word Me is an Alias Name for the Form where the Code runs. Instead of that you can use the reference like Forms![myForm]![CriteriaField]. Programmers prefer the much shorter reference Me.