473,545 Members | 2,048 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Loop within a loop ???

Hi,

I'm having trouble copying table data to new records.
I have two tables as follows:

*** Specifications (Table)
specification_I D (field) LINKED
product_ID (field)
specification_h eader (field)

_______________ _______________ __________

*** Specification_d etail (Table)
specification_d etail_ID (field)
specification_d etail_text (field)
specification_I D (field) LINKED

specification_I D in this table is linked to specification_I D in
Specifications.

_______________ _______________ __________
On a form, related by product_ID, 'Specifications ' fills a subform, no
problem.
When you click a record in this subform, the related records in subform
2 show, which is populated by Specification_d etail.

The problem I have is, when a new product is created, and a user
requests to copy a current product, everything is easy to copy as there
is a product_ID involved.
When the data from Specifications is copied to the new product, each
specification is given a new 'specification_ ID'.

Data from Specifications is copied via this code:

MySql4 = "INSERT INTO Specifications (product_ID, specification_h eader)
"
MySql4 = MySql4 & "SELECT " & NewProductCode & " as NewProductID,
Specifications. specification_h eader FROM Specifications "
MySql4 = MySql4 & "WHERE Specifications. product_ID = " & currentid
db.Execute MySql4, dbFailOnError

---------------------------------------

Now the table Specifications holds the copied records but with new IDs
for the newly created product.

How do I now copy the data from 'Specification_ detail' to the new
product ?
The specification_d etail_ID is created automatically, so this is ok,
but 'specification_ detail_text' needs to be copied from the current
selected product on the form and inserted along with the newly created
'specification_ ID' (see sql above)??

This is very difficult to get my head around.
I would appreciate any help you can offer.
Do I need to run a loop within a loop

Thanks in advance
David

Apr 12 '06 #1
1 1906
use the foreign key for the subtable.

SELECT ...
FROM ChildTable
WHERE ForeignKey=...

and then just turn that into an insert query. (Well, of course, you
have to capture the new PK from teh *new* record and then update those
records...)

Apr 12 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

32
3774
by: Wenjie | last post by:
Hello, We had a code review with the argument of whether "i" is out of scope as illustrated below: for (int i=0; i<2004; i++) { doSomething(i); }
3
2657
by: Gustavo Randich | last post by:
The following seems to be a bug. The execution returns rows 1,2. It should return 1,1. In fact, if I run the code within a stored procedure alone (not in a trigger), the loop doesn't overwrite the value of y (works well). create table test (a integer) @ create table debug1 (a integer) @ create trigger test_1 after insert on test...
3
3038
by: deko | last post by:
Problem: why doesn't this With block work? is it possible to have a For Each loop within a With block? With objWord .Documents.Add Template:=strTemplate, NewTemplate:=False, DocumentType:=0 For Each varBookmark In Array("ReturnAddress", "NameAddressBlock", "Salutation", "FullName") If DLookup(varBookmark, "tblTemplate", "template_ID = "...
14
2449
by: Crimsonwingz | last post by:
Need to calculate a sum based on a number of factors over a period of years. I can use formula ^x for some of it, but need totals to carry over in the sum and have only been able to do this thus far with a loop in a form. Basically, I have key sums Current savings Current Salary Current deposit amount
3
2526
by: Douglas | last post by:
Hi, In the loop for(i=0; i< h+1; i++); if h=10 say, then is h+1 evaluated every time or, between iterations, does the for loop remember that the condition i<11 is being applied? I'm guessing that it evaluates every time as it is possible that h may have been changed by the body of the loop.
34
3389
by: sushant | last post by:
hi all, suppose i have 2 loops one inside the other, like this 1) for(i=0;i<=100;i++) { for(j=0;j<=10;j++) { some code; }
13
14447
by: TrintCSD | last post by:
How can I reset the collections within a foreach to be read as a change from within the foreach loop then restart the foreach after collections has been changed? foreach(string invoice in findListBox.listBox2.Items) { listBox2.Items count changed, restart this foreach } Thanks for any help.
16
3500
by: Claudio Grondi | last post by:
Sometimes it is known in advance, that the time spent in a loop will be in order of minutes or even hours, so it makes sense to optimize each element in the loop to make it run faster. One of instructions which can sure be optimized away is the check for the break condition, at least within the time where it is known that the loop will not...
2
9422
by: rn5a | last post by:
In a ASP applicatiuon, the FOrm has a textbox & a select list where the admin can select multiple options. Basically the admin has to enter the name of a new coach in the textbox & select the soccer clubs which he will be coaching; thus he can select only one soccer club for a new coach or multiple soccer clubs. This is how I am trying it:...
2
3941
by: LostDeveloper via AccessMonster.com | last post by:
Relationship goes Certification can have multiple variations (any single variation satifies the certification), which require multiple course groups which require any one of the products assigned to the group. MS Access.. VBA.. got very many sub relationships and it takes about 30 seconds to see who is certified. But now my problem is I...
0
7415
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7675
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
1
7440
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
4963
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3470
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3451
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1902
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1030
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
726
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.