By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,986 Members | 1,944 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,986 IT Pros & Developers. It's quick & easy.

Copying record to a table several times

100+
P: 116
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
Share this Question
Share on Google+
10 Replies


FishVal
Expert 2.5K+
P: 2,653
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, 132 views)
Sep 11 '08 #2

100+
P: 116
Dear FishVal

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

Thank you

Jacc14
Sep 11 '08 #3

100+
P: 116
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

100+
P: 116
sorry FishVal. Table doesnt look so clear now I have submitted it. Hope it makes sense.

Best regards
Jacc14
Sep 11 '08 #5

FishVal
Expert 2.5K+
P: 2,653
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
Expert Mod 15k+
P: 31,347
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
Expert 2.5K+
P: 2,653
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

100+
P: 116
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
Expert 2.5K+
P: 2,653
You are welcome.

Best regards,
Fish
Sep 12 '08 #10

NeoPa
Expert Mod 15k+
P: 31,347
...
[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

Post your reply

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