Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Data Entry Validation, Multiple Conditions

Status
Not open for further replies.

Larry1216

Technical User
Nov 14, 2002
13
For validating Data Entry.

1. Date has to be between [Date1] and [Date2]

AND

it also has to be

2. If[Date3]="A" and [Date4]-[Date3]<15
- Do not permit data entry
- Otherwise give the validation text

It would be nice to have a different set of validation text for 1 and 2 but maybe thats asking too much.

Unfortunately, I am not up to visual basic expressions, just an analyst trying to make do.......

Searched thru the existing threads but did not see anything close.

Would appreciate any advisement on how to constuct this.
 
I did not understand this
If[Date3]="A"
So I did not check for this.
You may need to describe this problem a little clearer. On my form I had 5 fields
"dtmDate", "dtmOne", "dtmTwo", "dtmThree" and "dtmFour".

I verify all the values before the record is updated:
I check that all fields have a value
That "dtmDate" is between "dtmOne" and "dtmTwo"
and
The period between "dtmThree" and "dtmFour" is 14 days or less.
Code:
Private Sub Form_BeforeUpdate(Cancel As Integer)
 If IsNull(Me.dtmDate) Or IsNull(Me.dtmOne) Or IsNull(Me.dtmTwo) Or IsNull(Me.dtmThree) Or IsNull(Me.dtmFour) Then
  MsgBox "Date One, Two, Three and Four must have values"
  DoCmd.CancelEvent
  Exit Sub
ElseIf Not (Me.dtmDate > Me.dtmOne And Me.dtmDate < Me.dtmTwo) Then
   MsgBox "Date must be between date One and date Two"
   DoCmd.CancelEvent
   Exit Sub
 ElseIf Me.dtmFour - Me.dtmThree >= 15 Then
   MsgBox "The period between date Three and date Four must be 14 days or less"
   DoCmd.CancelEvent
   Exit Sub
 End If
 MsgBox "The dates are valid"
End Sub
If the conditions are not met the event is canceled and the record is not updated.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top