Access MS Access Field Question

Joined
Jun 3, 2011
Messages
23
Reaction score
1
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?
 
Joined
Jul 20, 2011
Messages
16
Reaction score
0
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.
 

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

Top