Wrox Programmer Forums
|
Access VBA Discuss using VBA for Access programming.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Access VBA section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old December 18th, 2006, 10:41 PM
Registered User
 
Join Date: Dec 2006
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default 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!
 
Old December 18th, 2006, 10:50 PM
Registered User
 
Join Date: Dec 2006
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I got it....

DoCmd.RunCommand acCmdSaveRecord





Similar Threads
Thread Thread Starter Forum Replies Last Post
Why doesn't this Insert Procedure work. beerOne ASP.NET 3.5 Basics 2 June 19th, 2008 09:59 AM
Why normal insert querry doesnot work simsimlhr C# 2 January 9th, 2006 03:26 AM
insert tigger dont work multiple kspiderman SQL Server 2000 1 October 21st, 2005 01:42 PM
update/insert work in queries but not on form jonicholson Access VBA 3 January 18th, 2005 06:05 PM
Insert method doesnot work shoakat Classic ASP Databases 3 November 22nd, 2004 07:46 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.