Only add one record in subform if criteria match

C

Charlie.Mitchell

I have a form named, lets say "a"

And a subform in it named "b"

form a is assigned to table "c"

form b is assigned to table "d"

Table "c" has a field named "bob"

What I want to do is if, "bob" = "x" the only allow the one entry in subform
b and display message only one entry allowed.



I started the following with the real names:
Private Sub Form_BeforeInsert(Cancel As Integer) ' This goes in subform "b"

If Me.CurrentRecord = 2 And Forms![a].[bob] = "x" ' This is OK
Then
'??????????????????????????????????????
Cancel = True 'This is where I am making
a mistake???????????????????????????????????????
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

Thanks
Charlie
 

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

Top