Insert won't work
Hi everyone! This one is a stumper to me.
I have a form that a user can create a new customer. The form is bound by tblContact. When the user fills out information, some fields are bound to that table. As the first piece of information is being entered, a PKContact is created (autonumber).
When the user is done, I have an insert statement that is on an "on click" event of a button. In the event, I capture some data including primary keys for company (PKCompany) and location (PKLocation). Here is my insert statement with a few lines of code:
NewCustomerNumber = (DMax("PKCustomer", "tblCustomer")) + 100121
DoCmd.Save
db.Execute "Insert into tblCustomer (CustomerNumber, FKTop, FKLocation, FKContact) values (" & NewCustomerNumber & "," & CompanyNamePK & "," & CompanyLocationPK & "," & Me.fldPKContact & ")"
DoCmd.Close acForm, "frmCustomerNew"
DoCmd.OpenForm "frmMenuOptions"
But, nothing gets inserted. If I simply take out "FKContact" from the insert and "me.fldPKContact" from the value, it works. So that tells me that is where the problem is.
I think that the record cannot be inserted into tblCustomer (with PKContact) until the new record being written in tblCustomerContact is "closed".
So, my question is, how do I do this?
Thanks for any help!
|