Sections & Grouping??

I

Ivan Debono

Hi all,

I use VB6 to automate Word to create documents from templates that I define.
One thing that I don't know if it's possible to do is "grouping". What do I
mean??

OK, for example I have these records:

Category1 SubCategory1 ItemA
Category1 SubCategory2 ItemB
Category1 SubCategory2 ItemF
Category2 SubCategory1 ItemC
Category2 SubCategory1 ItemD
Category3 SubCategory2 ItemE

In the document I would want them grouped as follows:

Category1
SubCategory1
ItemA
SubCategory2
ItemB
ItemF
Category2
SubCategory1
ItemC
ItemD
Category3
SubCategory2
ItemE

At the moment I'm doing this by looping through the records, and hardcoding
what fields I want to group by, and more code to check groups, add the
necessary autotextentries, set bookmarks, etc... Quite messy!!

Furthermore, I'd need it flexible enough to allow for a number of group
levels from 0 to n...

Is there a way to simplify this work???

Thanks,
Ivan
Ivan
 
P

Peter Hewett

Hi Ivan Debono

If each line is a paragraph you could define and use a set of styles with different left
indents. Then it's just a case of applying the correct style to the paragraph.

HTH + Cheers - Peter
 
J

Jezebel

I would do it like this:

Dim pLevels(1 to n) as string
Dim pIndex as long
Dim pIndex2 as long

'Iterate the records
For each record ...

'Check each field
For pIndex = 1 to n

'If it's different from this field in the previous record ...
if Field(pIndex) <> pLevels(pIndex) then

'Output the field at the style for this level
Output Field(pIndex), Style(pIndex)

'Remember the field encountered
pLevels(pIndex) = Field(pIndex)

'Clear the remembered values for all lower levels
For pIndex2 = pIndex + 1 to n
pLevels(pIndex2) = ""
Next

End if
Next
Next
 
I

Ivan Debono

Hmmm... I don't think it could work.

Take for example the report designer of Access. I add a group section for
Categories and another group section for Subcategories. Then I have the
details section. Access would then know how and what to place where and
when.

I need to mimic the same functionality in Word without hardcoding any
levels, indentation (groups don't need to be indented).

Is it possible?
 
P

Peter Hewett

Hi Ivan Debono

Word isn't a report generator so there are no grouping functions. It has to be done
manually, quite how this is done is dependent upon the data, any aggregation you require
and what you want in the way of formatting your data.

Going on your original data sample you'd obvious have to look for changes in the Category,
Subcategory and group/total your output based on these. But you knew that bit anyway.

Cheers - Peter


Hmmm... I don't think it could work.

Take for example the report designer of Access. I add a group section for
Categories and another group section for Subcategories. Then I have the
details section. Access would then know how and what to place where and
when.

I need to mimic the same functionality in Word without hardcoding any
levels, indentation (groups don't need to be indented).

Is it possible?

HTH + Cheers - Peter
 
I

Ivan Debono

Yeah I guess you're right... unfortunately :)

Peter Hewett said:
Hi Ivan Debono

Word isn't a report generator so there are no grouping functions. It has to be done
manually, quite how this is done is dependent upon the data, any aggregation you require
and what you want in the way of formatting your data.

Going on your original data sample you'd obvious have to look for changes in the Category,
Subcategory and group/total your output based on these. But you knew that bit anyway.

Cheers - Peter




HTH + Cheers - Peter
 
A

Alex Ivanov

I'd recommend to save each section of your report in a separate autotext
entry, formated as needed with bookmarks inserted, ie header, subheaders,
detail, footers... Then you can do something like
while not mainrc.eof
'insert main group header and populate it
'get details rs
while not detailsrs.eof
'inseart detail section and populate
detailsrs.movenext
wend
mainrs.movenext
wend
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top