Hi there
I have a continuous form, frmBuyerDetails with a list of Contacts and a subform called frmInvoice. The forms are linked as follows:
Link Master Fields: CurrentOwnerID (tblContacts)
Link Child Fields: ContactID (tblInvoices)
In the After Update Event of the combobox on the main form where I select the Buyer from 'tblContacts', I have an If statement to check if a record in tblInvoices exist where the ContactID and DogID are the same than the current record on frmBuyerDetails.
If 0 then an Invoice record should be created for that Buyer. If record exist then don't create another invoice. The reason why I include the DogID is that I might sell another puppy to this Buyer in the future in which case it should then create a new Invoice.
I do get an Run-Time error 3201 "You cannot add or change a record because a related record is required in table 'tblContacts'"
I tried the If statement checking only the ContactID and it worked perfectly.
Hope I made the scenario clear enough
I have a continuous form, frmBuyerDetails with a list of Contacts and a subform called frmInvoice. The forms are linked as follows:
Link Master Fields: CurrentOwnerID (tblContacts)
Link Child Fields: ContactID (tblInvoices)
In the After Update Event of the combobox on the main form where I select the Buyer from 'tblContacts', I have an If statement to check if a record in tblInvoices exist where the ContactID and DogID are the same than the current record on frmBuyerDetails.
If 0 then an Invoice record should be created for that Buyer. If record exist then don't create another invoice. The reason why I include the DogID is that I might sell another puppy to this Buyer in the future in which case it should then create a new Invoice.
I do get an Run-Time error 3201 "You cannot add or change a record because a related record is required in table 'tblContacts'"
I tried the If statement checking only the ContactID and it worked perfectly.
Hope I made the scenario clear enough
Code:
If DCount("ContactID", "tblInvoices", "ContactID= " & CurrentOwnerID & " And DogID = " & DogID) = 0 Then
strSQL = "INSERT INTO tblInvoices (ContactID) " & vbCrLf _
& "Values (" & Me.CurrentOwnerID & ");"
strSQL = "INSERT INTO tblInvoices (DogID) " & vbCrLf _
& "Values (" & Me.DogID & ");"
Debug.Print strSQL
CurrentDb.Execute strSQL, dbFailOnError
End If