Data validation issue - Help

  • Thread starter Sarah at DaVita
  • Start date
S

Sarah at DaVita

I have the following code in my form. I am trying to make the user enter a
number between 1000 and 2000 in control PTNR_InsideLE if the control named
PTNR_InsidePtnr = Yes but nothing if it is No. I keep getthing an error. I
have the code in the After Update event on the PTNR_InsidePtnr control. I
have tried putting it in the after update event on the PTNR_InsideLE control
but still get the error.

Private Sub PTNR_InsidePtnr_AfterUpdate(Cancel As Integer)
If Me.PTNR_InsidePtnr = "Yes" Then
If Not Me.PTNR_InsideLE Then
MsgBox "Enter Inside LE number between 1000 and 2000"
Cancel = True
Me.PTNR_InsideLE.Undo
End If
End If
End Sub

Can someone tell me what I am doing wrong?
 
M

mray29

The event you need to check is the PTNR_InsideLE Before UPdate event. You
need to check the value in Me.PTNR_InsidePtnr in this event to decide what
to do. It would be something like

Sub PNTR_InsideLE_BeforeUpdate()

If Me.PTNR_InsidePtnr = "Yes" then
If Me.PTNR_InsideLE <=1000 or Me.PTNR_InsideLE >2000 then
Cancel = 1
Msbox "You must enter a number between 1000 and 2000"
End if

End SUb

If you don't want the user to enter anything in that control if the value of
PTNR_InsidePntr is No, then when the form loads you'd want to check the value
of PTNR_InsidePntr. If it's No, set the Enabled property of PTNR_InsideLE to
False, so the user can't enter anything in it. Otherwise set it to yes.

You can also call the After_Update event of PTNR_InsidePntr to when the
value is set to yes, you enable the other control, otherwise you disable it.
 
Top