Validation

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

Guest

I have a field called Order ID, and in this field, I could have many Orders
(e.g. many items) under the same Order ID number.
How do I add a validation to this Order ID so that the maximum number of
items ordered under an Order ID is 5? Basically, allowing the Order ID to
duplicate no more than five times.

I have this code, but it don't seem to work, I right clicked Order ID in the
form, chose Code builder, copy and pasted it, and there was an error in the
code where it says: "RS.OpenRecordSet"

Private Sub Form_BeforeInsert(Cancel As Integer)
Dim RS As Recordset

Set RS = Me.RecordsetClone
If RS.RecordCount > 0 Then
RS.MoveLast
Else
RS.OpenRecordset
End If
If RS.RecordCount > 4 Then
Cancel = True
MsgBox "You are only allowed to enter 5 records!"
End If

RS.Close
Set RS = Nothing
End Sub
 
When you set RS to the RecordSetClone, you opened the recordset. What
happens if you remove the Else and RS.OpenRecordset?
 
Back
Top