Data validation issue - Help

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

Guest

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?
 
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.
 

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

Similar Threads

if statement 5
Before Update 6
VB Coding Assistance 2
Excel Is it possible to ask a question within a question? 0
Data Validation 10
date problem 2
Event Procedure with ACCDE 3
Blank Fields in Report 2

Back
Top