473,326 Members | 2,102 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,326 software developers and data experts.

Copying record to a table several times

116 100+
Hi
I am sure there is an easy way to do this but I have exhausted all avenues.

I have some label data in a table which I want to copy to an identical table. However the first label I may only want one of that label data copying to the new table. The second label I may want seven of that label data copying to the new table. I have a count field called "nooflabels"! which has 1 in the first record and 7 in the second.

I have created an append query and set up a macro to run then created a button in my form to run that macro

Expand|Select|Wrap|Line Numbers
  1. Dim thecount As Integer
  2.     Dim stDocName As String
  3. thecount = Me.Nooflabels
  4.  
  5.  
  6. stDocName = "Create_duplicatedespatches"
  7. DoCmd.RunMacro stDocName, thecount
  8.  
Problem is that the query doesnt treat each record separately so I either end up with 1 of each record or 7 of each record.

How can I split this out.

Am feel I am going down the wrong track and wondering if I should be using loop although i have never used this before.

Please could someone advice on this.

Thanks

jacc14
Sep 11 '08 #1
10 2408
FishVal
2,653 Expert 2GB
Hi, jacc14.

It is normally done in VBA via recordset iteration. I'm sure you will receive numerous advices of how it could be done.

So I would suggest you pure SQL solution. Just to show feasibility of this approach. See attachment.

Regards,
Fish
Attached Files
File Type: zip MultiplyRecords.zip (8.9 KB, 256 views)
Sep 11 '08 #2
jacc14
116 100+
Dear FishVal

This is excellent. I have applied and it works a treat.

Thank you

Jacc14
Sep 11 '08 #3
jacc14
116 100+
Dear FishVal
I hope you dont mind me directing this question to yourself but you already know where I am going with this and I am struggling again

The table which I have now produced looks like this.
Expand|Select|Wrap|Line Numbers
  1.  ID         Label        Value   Count                Unique Number 
  2.  1         Label1         50      7                           1
  3.  1         Label1         50      7                           2
  4.  1         Label1         50      7                           3 
  5.  1         Label1         50      7                           4
  6.  1         Label1         50      7                           5
  7.  1         Label1         50      7                           6
  8.  1         Label1         50      7                           7
  9.  2         Label2        100      1                           1
I now need to assign a unique number by each group of records. This is so that when I print the labels it will say 1 of 7, 2 of 7, 3 of 7, 4 of 7, 5 of 7, 6 of 7, 7 of 7 and then for label2 it will say 1 of 1. This means that each batch of labels will have there own group of numbers. See above under Unique Number.

I have used DMAX in a form before and know that this is the answer but I really want to put it in the sql query that you have helped me with as this is the part that creates the duplicated records. Is this possible. Sorry to be a pain.

Many thanks

Jacc14
Sep 11 '08 #4
jacc14
116 100+
sorry FishVal. Table doesnt look so clear now I have submitted it. Hope it makes sense.

Best regards
Jacc14
Sep 11 '08 #5
FishVal
2,653 Expert 2GB
Hello, jacc14.

Below is a query (in context of the attachment tables):
Expand|Select|Wrap|Line Numbers
  1. SELECT tblItems.keyID, tblItems.txtText, tblMultipliers.lngMultiplier  & ' of ' & tblItems.lngQuantity AS txtCopyNumber
  2. FROM tblItems INNER JOIN tblMultipliers ON tblItems.lngQuantity >= tblMultipliers.lngMultiplier;
  3.  
Regards,
Fish
Sep 11 '08 #6
NeoPa
32,556 Expert Mod 16PB
I may be way off base here Fish, but shouldn't that be something more like (I'm working with no meta-data) :
Expand|Select|Wrap|Line Numbers
  1. ...
  2. FROM tblItems INNER JOIN tblMultipliers
  3.   ON tblItems.keyID = tblMultipliers.[SomeIDField]
Sep 11 '08 #7
FishVal
2,653 Expert 2GB
Ok. I would like to clarify the basics od the proposed solution.
  • [tblMultipliers] is an auxiliary table storing sequential natural numbers {1,2,3,4 ... N}.
    metadata:
    Expand|Select|Wrap|Line Numbers
    1. Field           Type
    2. [lngMultiplier] Number(Long)
    3.  
  • Table join is used to combine records from [tblMultipliers] where [lngMultip[lier] <= [ ... tblItems field storing required number of copies ... ] with a record from [tblItems].
    Expand|Select|Wrap|Line Numbers
    1. SELECT tblItems.keyID, tblItems.txtText, tblMultipliers.lngMultiplier  & ' of ' & tblItems.lngQuantity AS txtCopyNumber
    2. FROM tblItems INNER JOIN tblMultipliers ON tblItems.lngQuantity >= tblMultipliers.lngMultiplier;
    3.  

Regards,
Fish
Sep 12 '08 #8
jacc14
116 100+
Dear FishVal

I have applied the code and its spot on. Thanks for your help. Much appreciated.

Best regards

Jacc14
Sep 12 '08 #9
FishVal
2,653 Expert 2GB
You are welcome.

Best regards,
Fish
Sep 12 '08 #10
NeoPa
32,556 Expert Mod 16PB
...
[tblMultipliers] is an auxiliary table storing sequential natural numbers {1,2,3,4 ... N}.
metadata:
Expand|Select|Wrap|Line Numbers
  1. Field           Type
  2. [lngMultiplier] Number(Long)
...
Ah, that makes more sense now.
Sep 12 '08 #11

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Jason | last post by:
In enterprise manager I am copying a table from one database to another. I am using the dts wizard to import the data. After I successfully import the data, I open both tables to compare the...
8
by: DP | last post by:
I read some articles and post how to optimize te speed of asp pages regarding opening and closing DB connections but I am still not sure about this. Is it true that it doesn't matter how many...
0
by: donal.conlon | last post by:
I'm using a few threads to run a commandline tool and read the outputs. What I want to do is run the tool several times with different arguments every time. i.e.run the process in its own thread,...
0
by: Rahul | last post by:
Earlier this evening i posted a question that my debug point is hit several times, But after I published the application. I could significantly see less round trip per request for Application_Begin...
1
by: pedro8ae | last post by:
I have a table with multiple records and one field that determine wheter or not the record is in use (Yes/No). I create a Query to list all the Yes in that table BUT, when I list or run my query...
0
by: francisantony | last post by:
Hi, In my ASP.NET2.0 application, the Session is restarting several times in the same instance of the browser. I have specified the Mode = InProc of the 'session state' tag in the web.config. ...
3
by: lezilgeorge | last post by:
I wanted to run an undate query in a for loop several times.....But When i run this only the 1 st row is getting updated and shows an error which says String or binary number is truncated, i am using...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....

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.