lsimonelli via AccessMonster.com wrote:
On a form, how do I require entry of a field based on the data in another
field? I do not want to require at the table level.
I have a field that the user selects where a refund goes. If they choose
"Other", field "Other Explanation" cannot be Null. If they choose
"Producer" then field "Producer Code" cannot be Null.
Your help would be greatly appreciated!!
I created a table with 3 text fields; Code, Desc1, and Desc2. Here's
the code for the form. Sub LockFields permits mod of field based on code.
Private Sub Form_Current()
LockFields
End Sub
Private Sub Code_AfterUpdate()
LockFields
If Me.Code = 1 Then
Me.Desc1.SetFocus
Me.Desc2 = Null
Else
Me.Desc2.SetFocus
Me.Desc1 = Null
End If
End Sub
Private Sub Desc1_Exit(Cancel As Integer)
If Me.Code = 1 And IsNull(Me.Desc1) Then
MsgBox "Enter Description 1"
Cancel = True
End If
End Sub
Private Sub Desc2_Exit(Cancel As Integer)
If Me.Code = 2 And IsNull(Me.Desc2) Then
MsgBox "Enter Description 2"
Cancel = True
End If
End Sub
Private Sub LockFields()
Dim intCode As Integer
intCode = Nz(Me.Code, 0)
Me.Desc1.Locked = (intCode <1)
Me.Desc2.Locked = (intCode <2)
End Sub
Be young
http://www.youtube.com/watch?v=hiFOvrDAxxw