PC Review


Reply
Thread Tools Rate Thread

code to create Box x of xx

 
 
bhorwitz
Guest
Posts: n/a
 
      3rd Sep 2008
I need to group the data by Id and assign a box # and populate the Box field
with Box x of xx. See example below.

Id Description Box
123 1 Box 1 of 3
123 2 Box 2 of 3
123 5 Box 3 of 3
456 1 Box 1 of 2
456 2 Box 2 of 2

I am assuming that the best way to do this is via some code that loops thru,
but since I dont know VBA that well Im not sure how to do it.

any help would be appreciated, even if it is pointing me to the right place
to research it.

Thank you
Bob

 
Reply With Quote
 
 
 
 
John Spencer
Guest
Posts: n/a
 
      3rd Sep 2008
One method would be to use something like the following query.

SELECT YA.ID
, YA.Description
, Count(YB.ID) +1 as BoxNumber
, (SELECT Count(ID) FROM YourTable as YC WHERE YC.ID = YA.ID) as TotalBoxes
FROM YourTable as Ya LEFT JOIN YourTable as YB
ON YA.ID =YB.ID
AND YA.Description < YB.Description
GROUP BY YA.ID, YA.Description


'====================================================
John Spencer
Access MVP 2002-2005, 2007-2008
The Hilltop Institute
University of Maryland Baltimore County
'====================================================


bhorwitz wrote:
> I need to group the data by Id and assign a box # and populate the Box field
> with Box x of xx. See example below.
>
> Id Description Box
> 123 1 Box 1 of 3
> 123 2 Box 2 of 3
> 123 5 Box 3 of 3
> 456 1 Box 1 of 2
> 456 2 Box 2 of 2
>
> I am assuming that the best way to do this is via some code that loops thru,
> but since I dont know VBA that well Im not sure how to do it.
>
> any help would be appreciated, even if it is pointing me to the right place
> to research it.
>
> Thank you
> Bob
>

 
Reply With Quote
 
bhorwitz
Guest
Posts: n/a
 
      3rd Sep 2008
Thank you I will give that a Try

"John Spencer" wrote:

> One method would be to use something like the following query.
>
> SELECT YA.ID
> , YA.Description
> , Count(YB.ID) +1 as BoxNumber
> , (SELECT Count(ID) FROM YourTable as YC WHERE YC.ID = YA.ID) as TotalBoxes
> FROM YourTable as Ya LEFT JOIN YourTable as YB
> ON YA.ID =YB.ID
> AND YA.Description < YB.Description
> GROUP BY YA.ID, YA.Description
>
>
> '====================================================
> John Spencer
> Access MVP 2002-2005, 2007-2008
> The Hilltop Institute
> University of Maryland Baltimore County
> '====================================================
>
>
> bhorwitz wrote:
> > I need to group the data by Id and assign a box # and populate the Box field
> > with Box x of xx. See example below.
> >
> > Id Description Box
> > 123 1 Box 1 of 3
> > 123 2 Box 2 of 3
> > 123 5 Box 3 of 3
> > 456 1 Box 1 of 2
> > 456 2 Box 2 of 2
> >
> > I am assuming that the best way to do this is via some code that loops thru,
> > but since I dont know VBA that well Im not sure how to do it.
> >
> > any help would be appreciated, even if it is pointing me to the right place
> > to research it.
> >
> > Thank you
> > Bob
> >

>

 
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
Create a DSN using code Troy Microsoft Access 2 13th Jun 2006 09:44 PM
Create a newworksheet with VBA code and put VBA code in the new worksheet module ceshelman Microsoft Excel Programming 4 15th Jun 2005 04:37 PM
How to create event code from code? Todd P Microsoft Access 1 7th Dec 2004 12:56 AM
Can I create a PDF using VB code? =?Utf-8?B?bGFuZW0=?= Microsoft Dot NET Framework Forms 1 23rd Sep 2004 04:23 PM
How to create a new DB with code? Kline Microsoft Dot NET 7 8th Oct 2003 07:28 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 01:55 PM.