473,386 Members | 2,114 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,386 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 2411
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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...
0
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,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.