Stop adding record in subform after record count = 1

  • Thread starter Thread starter Charlie
  • Start date Start date
C

Charlie

Can someone help in in what to put after the THEN statment to allow one
entry if the Record count is =>1 in the Before insert or should I set the
probert after the first entry?


This code is in Before insert event in Sub Form

Private Sub Form_BeforeInsert(Cancel As Integer) ' This goes in subform "b"
If Me.CurrentRecord = 2 And Forms![MainForm].[Field in Main Form] =
"variable"
Then
Cancel = True '??????
MsgBox "You can only have one invoice per bob entry", vbInformation,
"Data Error"

End If

'From here I want to go back to the form as if I only have
one entry now and sitting as if I just called it up.

End Sub


Thank You
Charlie
 
In the subforms forms OnDirty event
Put the following code
Private Sub Form_Dirty(Cancel As Integer)
If Me.NewRecord = True Then
Me.DataEntry = False
End If
End Sub
That’s it
Works Like a Dream!
Takes the user back to the previous value when they try to type in a new value.

Good Luck
 
Last edited:
Back
Top