PC Review


Reply
Thread Tools Rate Thread

Copy old subform records to new Form's subform

 
 
Billp
Guest
Posts: n/a
 
      15th Jun 2009
Hi,

I have so far got

Dim strSql As String 'SQL Satement



strSql = "INSERT INTO [tblCustomerContacts] " & _
"SELECT * " & _
"FROM [tblCustomerContacts] WHERE [CustomerID] = " &
Me!Cust_Alias_ID.Column(0) & ";"

DBEngine(0)(0).Execute strSql, dbFailOnError

The main form/table has an Autonumber ID called "Customer_Record_ID" and is
the main key.
A feild called "CustomerID" is a unique 6 letter identifier for the form.

The subtable is linked to the main form/table via "CustomerID" in a many to
one.

Upon selecting the "CustomerID" via a combo box I am trying to copy all
records in a subtable relating to that 'CustomerID" and paste them into the
new subform as part of the new record under the new "CustomerID".

The new records are a duplicate of the old reference. Say the old refernce
had 9 records - I need those 9 reords to copy to the new subform and to be
linked to it by the new "CustomerID".

I am not having much luck.
I have looked at Allen Brownes duplicate example - to no avail.


Any help really really appreciated.


 
Reply With Quote
 
 
 
 
Graham Mandeno
Guest
Posts: n/a
 
      15th Jun 2009
Hi Bill

Currently you are saying:

INSERT INTO [tblCustomerContacts]
SELECT * FROM [tblCustomerContacts] WHERE ...

Because you are using SELECT *, you are selecting ALL the fields from the
records you want to append, including CustomerID.

What you need to do is make a list of all the fields in
[tblCustomerContacts] EXCEPT CustomerID, and select those fields along with
the new CustomerID value. You should also omit any autonumber primary key
field, if you have one.

You can assign a list of field names to a variable and use it twice in your
SQL string - for example:

strOtherFields = ", FirstName, LastName, JobTitle, OfficePhone, Mobile"

strSQL = "Insert into tblCustomerContacts (CustomerID" _
& strOtherFields & ") SELECT " & lngNewCustomerID _
& strOtherFields & " from tblCustomerContacts WHERE CustomerID=" _
& Me!Cust_Alias_ID.Column(0) & ";"

lngNewCustomerID is the autonumber PK value of the new record that you have
just added.

--
Good Luck :-)

Graham Mandeno [Access MVP]
Auckland, New Zealand


Also,
"Billp" <(E-Mail Removed)> wrote in message
news:A4D4B599-EB4F-46D6-AF64-(E-Mail Removed)...
> Hi,
>
> I have so far got
>
> Dim strSql As String 'SQL Satement
>
>
>
> strSql = "INSERT INTO [tblCustomerContacts] " & _
> "SELECT * " & _
> "FROM [tblCustomerContacts] WHERE [CustomerID] = " &
> Me!Cust_Alias_ID.Column(0) & ";"
>
> DBEngine(0)(0).Execute strSql, dbFailOnError
>
> The main form/table has an Autonumber ID called "Customer_Record_ID" and
> is
> the main key.
> A feild called "CustomerID" is a unique 6 letter identifier for the form.
>
> The subtable is linked to the main form/table via "CustomerID" in a many
> to
> one.
>
> Upon selecting the "CustomerID" via a combo box I am trying to copy all
> records in a subtable relating to that 'CustomerID" and paste them into
> the
> new subform as part of the new record under the new "CustomerID".
>
> The new records are a duplicate of the old reference. Say the old refernce
> had 9 records - I need those 9 reords to copy to the new subform and to be
> linked to it by the new "CustomerID".
>
> I am not having much luck.
> I have looked at Allen Brownes duplicate example - to no avail.
>
>
> Any help really really appreciated.
>
>



 
Reply With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Copy records from Subform A to Subform B Jane Microsoft Access 2 15th Aug 2009 06:22 PM
subform combo to filter based on other subform...technically mainform's other subform records. nospam@thankyou.com Microsoft Access 0 15th Sep 2006 07:51 PM
prevent closing a form and go to subform if no records in subform??? tlyczko Microsoft Access Form Coding 4 17th Apr 2006 12:00 PM
Urgent !!! - Values from Subform - #Error if no records in Subform and Only grabs first subform record Greg Microsoft Access Forms 0 17th Feb 2005 01:12 PM
Copy/Paste Records with Multiple Subform Records Max Smart Microsoft Access Form Coding 2 16th Sep 2004 03:26 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 11:29 AM.