Populating fields ... one or the other

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have 2 numeric fields but based on users choice only one can have a value
(the other can have 0) at a time. How can I apply this rule along with a
warning if attempts to populate second field.

Thanks.
Scott
 
ScottNC said:
I have 2 numeric fields but based on users choice only one can have a value
(the other can have 0) at a time. How can I apply this rule along with a
warning if attempts to populate second field.


In a form, use each text box's BeforeUpdate event to test
the other text box's value:

Sub text2_BeforeUpdate(Cancel ...
If Nz(Me.text1, 0) <> 0 Then
MsgBox "text1 must be cleared before setting text2"
Me.text2.Undo
Cancel = True
End If
End Sub
 
Or you can force it the other way.


Sub text2_After_Update(Cancel ...
If Nz(Me.text2, 0) <> 0 Then
Me.text1 = 0
End If
End Sub

And the revers for text1 Afterupdate event.


Ron
 
Back
Top