I am still getting the hang of working with inserting variables into the
document.

I am in Word97 where their is no InsertRowAbove / InsertRowBelow.

So to add some rows to the bottom of the table I need to first set the range
to the line below the bottom of the table then do my insert, I am using
autotext to insert 4 rows that are preformatted.

But what I want to know is the best way to get to the first line below the
last row of the first table?

Cheers

-Al

Table, Listbox & Array by Al

Al
Fri Oct 10 17:41:22 CDT 2003

Jean-Guy and Jonathon know the background to this question, so if your
reading this guys I would love to hear your thoughts.

I have a series of listboxes which ask for;
Name, Address, Town, DOB, Age, Job.

This is then saved as an array, which is used to populate a list box with
the above information.

Each ROW in the listbox represents a person, but because of Redim Preserve
affecting only the columns each COLUMN of the array is a person. They are
transposed between the listbox and the array.....

I am at the stage now where I am inserting the personal info into a table in
a template.

The table is the first table in the template and is 4 x 4. If their is more
than one person additional tables (which contain formatting) are inserted by
way of a autotext entry.

Now I could insert each bit of personal information bit by bit with
something like:

For r = 0 To numberinlistbox
.Tables(1).Cell((r * 4) + 1, 2).Range.Text = ListBox2.List(r, 0) ' Insert
Full Name
Next r

But that is gonna mean 6 loops, that loop for each person, and typically
talking about 2-3 people, and is rather ugly way to do it.

I have read on a MVP website that its better to insert as much data as
possible at once, and that to do it, peice by peice is very slow.

Anybody know a way to do this quicker?

The end result should look like:

Name1 DOB: 12/12/80
Address1 AGE: 23
Town1 OCC: Builder

Where DOB/AGE/OCC are in the autotext table.....

Any anybody able to help point me in the right direction?

Ta

-Al









Re: Line below table by Doug

Doug
Fri Oct 10 18:47:46 CDT 2003

Hi Al,

The following code will add a row to the bottom of the first table in the
document.

ActiveDocument.Tables(1).Rows.Add

Please post any further questions or followup to the newsgroups for the
benefit of others who may be interested. Unsolicited questions forwarded
directly to me will only be answered on a paid consulting basis.

Hope this helps
Doug Robbins - Word MVP
"Al & Cay Grant" <bigal_nz@hotmail.com> wrote in message
news:bm7bg6$84u$1@lust.ihug.co.nz...
> I am still getting the hang of working with inserting variables into the
> document.
>
> I am in Word97 where their is no InsertRowAbove / InsertRowBelow.
>
> So to add some rows to the bottom of the table I need to first set the
range
> to the line below the bottom of the table then do my insert, I am using
> autotext to insert 4 rows that are preformatted.
>
> But what I want to know is the best way to get to the first line below the
> last row of the first table?
>
> Cheers
>
> -Al
>
>
>
>



Re: Table, Listbox & Array by Doug

Doug
Fri Oct 10 18:51:20 CDT 2003

Hi Al,

This is a somewhat different approach that adds, in this case an employee to
a table in a document and also populates the listbox with the employees at
the same time. It will give you the details for each person on a separate
row rather than in columns (which would be difficult to work with):

Private Sub cmdAddEmployee_Click()
'Check that data has been entered into both the FirstName and the LastName
controls.
If Len(Trim(txtFirstName)) = 0 Or Len(Trim(txtLastName)) = 0 Then
MsgBox "You must enter both the first name and the last name of the
Employee"
Exit Sub
End If
'Get the path to the file containing the Training Tracker Data.
PathofSystemFiles =
System.PrivateProfileString("C:\RNMFormSettings.txt", "MacroSettings", _
"TrainingTrackerDataFileSource")
'Open the TrainingData File
Set sourcedoc = Documents.Open(PathofSystemFiles & "\TrainingData.doc",
, , False)
'Determine what action to take based on the caption that appears on the
button
If cmdAddEmployee.Caption = "Save" Then 'modify existing record
'Locate the row containing the employee
For j = 2 To sourcedoc.Tables(2).Rows.Count
Set myitem = sourcedoc.Tables(2).Cell(j, 1).Range
myitem.End = myitem.End - 1
If myitem = i Then
i = j
Exit For
End If
Next j
Else ' Add new record
i = sourcedoc.Tables(2).Rows.Count
Set myitem = sourcedoc.Tables(1).Cell(i, 1).Range
sourcedoc.Tables(2).Rows.Add
i = i + 1
sourcedoc.Tables(2).Cell(i, 1).Range.Text = Val(myitem) + 1
End If
'Enter the revised data into the Course Details table and Refresh the
ListCourses ListBox
sourcedoc.Tables(2).Cell(i, 2).Range.Text = txtEmployeeNumber
sourcedoc.Tables(2).Cell(i, 3).Range.Text = txtLastName
sourcedoc.Tables(2).Cell(i, 4).Range.Text = txtFirstName
sourcedoc.Tables(2).Cell(i, 5).Range.Text = TxtDepartment
sourcedoc.Tables(2).Cell(i, 6).Range.Text = txtPhone
sourcedoc.Tables(2).Cell(i, 7).Range.Text = txtEmail
sourcedoc.Save
'Sort the Employee list by Last Name, First Name
sourcedoc.Tables(2).Sort ExcludeHeader:=True, FieldNumber:="Column 3",
SortFieldType _
:=wdSortFieldAlphanumeric, SortOrder:=wdSortOrderAscending,
FieldNumber2:="Column 4", _
SortFieldType2:=wdSortFieldAlphanumeric,
SortOrder2:=wdSortOrderAscending
'Populate the ListEmployees listbox
Call PopulateListEmployees
'Clear the fields in the FrameNewEmployeeDetails
txtEmployeeNumber = ""
txtFirstName = ""
txtLastName = ""
TxtDepartment = ""
txtPhone = ""
txtEmail = ""
'Enable the ListEmployees control
ListEmployees.Enabled = True
'Modify the caption of the FrameNewEmployeeDetails and hide it
FrameNewEmployeeDetails.Visible = False
FrameNewEmployeeDetails.Caption = "New Employee Details"
'Modify the caption of the cmdAddEmployee button and disable the buton
cmdAddEmployee.Caption = "Add Employee to List"
cmdAddEmployee.Enabled = False
'Enable the NewEmployee button
cmdNewEmployee.Enabled = True
'Hide the cmdCancel Button
cmdCancelEmployee.Visible = False

End Sub

This is the PopulateListEmployees routine that is called by the above code:

Sub PopulateListEmployees()
'Get the number or courses = number of rows in the table of course details
less one
i = sourcedoc.Tables(2).Rows.Count - 1
'Get the number of columns in the table of Employees
j = sourcedoc.Tables(2).Columns.Count
'Set the number of columns in the Listbox to match
'the number of columns in the table of Employees
ListEmployees.ColumnCount = j + 1
'Define an array to be loaded with the Employee data
Dim MyArray() As Variant
'Load client data into MyArray
ReDim MyArray(i, j)
For n = 0 To 1
For m = 0 To i - 1
Set myitem = sourcedoc.Tables(2).Cell(m + 2, n + 1).Range
myitem.End = myitem.End - 1
MyArray(m, n) = myitem.Text
Next m
Next n
For m = 0 To i - 1
Set Lname = sourcedoc.Tables(2).Cell(m + 2, 3).Range
Lname.End = Lname.End - 1
Set Fname = sourcedoc.Tables(2).Cell(m + 2, 4).Range
Fname.End = Fname.End - 1
MyArray(m, 2) = Lname.Text & ", " & Fname.Text
Next m
For n = 2 To j - 1
For m = 0 To i - 1
Set myitem = sourcedoc.Tables(2).Cell(m + 2, n + 1).Range
myitem.End = myitem.End - 1
MyArray(m, n + 1) = myitem.Text
Next m
Next n
'Load data into the ListCourses listbox
ListEmployees.List() = MyArray
'Close the file containing the client details
sourcedoc.Close SaveChanges:=wdDoNotSaveChanges
Application.ScreenUpdating = True
End Sub

This is the code that you would need to delete an employee form the table in
the document as well as from the listbox:

Private Sub CmdDeleteEmployee_Click()
'Display a warning message
Dim Msg, Style, Title, Response, MyString
Msg = "You are about to delete the selected employee. Do you want to
continue ?" ' Define message.
Style = vbYesNo + vbCritical + vbDefaultButton2 ' Define buttons.
Title = "Warning" ' Define title.
Response = MsgBox(Msg, Style, Title)
If Response = vbYes Then ' User chose Yes.
'Disable the cmdDeleteEmployee button
CmdDeleteEmployee.Enabled = False
'Get the Row Number for the Employee who is to be deleted.
i = ListEmployees.Column(0)
'Open the TrainingData File
Set sourcedoc = Documents.Open(PathofSystemFiles &
"\TrainingData.doc", , , False)
'Locate the row containing the employee
For j = 2 To sourcedoc.Tables(2).Rows.Count
Set myitem = sourcedoc.Tables(2).Cell(j, 1).Range
myitem.End = myitem.End - 1
If myitem = i Then
i = j
Exit For
End If
Next j
'Delete the row containing the data for the employee
sourcedoc.Tables(2).Rows(i).Delete
'Save and Close the TrainingData file
sourcedoc.Close wdSaveChanges
'Remove the item from the listEmployees
ListEmployees.RemoveItem (ListEmployees.ListIndex)
Else ' User chose No.
Exit Sub
End If
End Sub
--
Please post any further questions or followup to the newsgroups for the
benefit of others who may be interested. Unsolicited questions forwarded
directly to me will only be answered on a paid consulting basis.

Hope this helps
Doug Robbins - Word MVP
"Al & Cay Grant" <bigal_nz@hotmail.com> wrote in message
news:bm7cj1$8rr$1@lust.ihug.co.nz...
> Jean-Guy and Jonathon know the background to this question, so if your
> reading this guys I would love to hear your thoughts.
>
> I have a series of listboxes which ask for;
> Name, Address, Town, DOB, Age, Job.
>
> This is then saved as an array, which is used to populate a list box with
> the above information.
>
> Each ROW in the listbox represents a person, but because of Redim Preserve
> affecting only the columns each COLUMN of the array is a person. They are
> transposed between the listbox and the array.....
>
> I am at the stage now where I am inserting the personal info into a table
in
> a template.
>
> The table is the first table in the template and is 4 x 4. If their is
more
> than one person additional tables (which contain formatting) are inserted
by
> way of a autotext entry.
>
> Now I could insert each bit of personal information bit by bit with
> something like:
>
> For r = 0 To numberinlistbox
> .Tables(1).Cell((r * 4) + 1, 2).Range.Text = ListBox2.List(r, 0) ' Insert
> Full Name
> Next r
>
> But that is gonna mean 6 loops, that loop for each person, and typically
> talking about 2-3 people, and is rather ugly way to do it.
>
> I have read on a MVP website that its better to insert as much data as
> possible at once, and that to do it, peice by peice is very slow.
>
> Anybody know a way to do this quicker?
>
> The end result should look like:
>
> Name1 DOB: 12/12/80
> Address1 AGE: 23
> Town1 OCC: Builder
>
> Where DOB/AGE/OCC are in the autotext table.....
>
> Any anybody able to help point me in the right direction?
>
> Ta
>
> -Al
>
>
>
>
>
>
>
>



Re: Table, Listbox & Array by JGM

JGM
Fri Oct 10 19:35:21 CDT 2003

Hi Al,

Your array, if I remember correctly had 10 rows and as many column as there
were people.
If in the end you are using only 6 data type per person, then you do not
need to put 10 coloumns everything in the array.

In any case, you should have something like: MyArray(5 , x) were x = number
of people.

You use that array to populate the combobox. Then the user used the combobox
to confirm that everything is OK (I strongly recommend that you give the
user a way of reviewing, adding, modifying, deleting names). Once everything
has been confirmed, your array is ready to go.

You can use the array, not only the combobox, to populate your table.

Find the logic of your table and combine it to your array. You are going to
have to figure out the logic behind inserting the text in the appropriate
places.

Prepare an Autotext that has all the rows/cells neccessary for one person,
then, before inserting the text, insert as many Autotext as you have people,
then either place the cursor, or use the range object to define the table
you need for the job.

For example:

With MyRange.Tables(1)

For r = 0 To UBound(MyArray, 2) 'Look for UBound in the Help
.Cell((r * 4) + 1, 2).Range.Text = MyArray(0 , r)
.Cell((r * 4) + 1, 4).Range.Text = MyArray(1 , r)
.Cell((r * 4) + 2, 2).Range.Text = MyArray(2 , r)
.Cell((r * 4) + 2, 4).Range.Text = MyArray(3 , r)
.Cell((r * 4) + 3, 2).Range.Text = MyArray(4 , r)
'etc.
Next r

End With

Or something like that...

HTH
Cheers.
--
_______________________________________
Jean-Guy Marcil
jmarcil@sympatico.ca

"Al & Cay Grant" <bigal_nz@no$spam.remove.hotmail.com> a écrit dans le
message de news: bm7cj1$8rr$1@lust.ihug.co.nz...
> Jean-Guy and Jonathon know the background to this question, so if your
> reading this guys I would love to hear your thoughts.
>
> I have a series of listboxes which ask for;
> Name, Address, Town, DOB, Age, Job.
>
> This is then saved as an array, which is used to populate a list box with
> the above information.
>
> Each ROW in the listbox represents a person, but because of Redim Preserve
> affecting only the columns each COLUMN of the array is a person. They are
> transposed between the listbox and the array.....
>
> I am at the stage now where I am inserting the personal info into a table
in
> a template.
>
> The table is the first table in the template and is 4 x 4. If their is
more
> than one person additional tables (which contain formatting) are inserted
by
> way of a autotext entry.
>
> Now I could insert each bit of personal information bit by bit with
> something like:
>
> For r = 0 To numberinlistbox
> .Tables(1).Cell((r * 4) + 1, 2).Range.Text = ListBox2.List(r, 0) ' Insert
> Full Name
> Next r
>
> But that is gonna mean 6 loops, that loop for each person, and typically
> talking about 2-3 people, and is rather ugly way to do it.
>
> I have read on a MVP website that its better to insert as much data as
> possible at once, and that to do it, peice by peice is very slow.
>
> Anybody know a way to do this quicker?
>
> The end result should look like:
>
> Name1 DOB: 12/12/80
> Address1 AGE: 23
> Town1 OCC: Builder
>
> Where DOB/AGE/OCC are in the autotext table.....
>
> Any anybody able to help point me in the right direction?
>
> Ta
>
> -Al
>
>
>
>
>
>
>
>



Re: Table, Listbox & Array by Al

Al
Fri Oct 10 22:24:00 CDT 2003

Hi Jean-Guy & Doug,

Yes it does actually have 10, but not all ten are used at this stage, though
they are later.

I see in both your example and Doug's example that the data is inserted one
piece at a time.

I am sur eyou guys have seen it, but if you have'nt have a look at;
http://www.mvps.org/word/FAQs/TblsFldsFms/FastTables.htm
point number 5 in particular, and 8 and 10.

Does that relate to this scenario?

-Al


The MVP site I read on tables
"JGM" <no-spam@leaveme.alone> wrote in message
news:eb7vf74jDHA.2444@TK2MSFTNGP09.phx.gbl...
> Hi Al,
>
> Your array, if I remember correctly had 10 rows and as many column as
there
> were people.
> If in the end you are using only 6 data type per person, then you do not
> need to put 10 coloumns everything in the array.
>
> In any case, you should have something like: MyArray(5 , x) were x =
number
> of people.
>
> You use that array to populate the combobox. Then the user used the
combobox
> to confirm that everything is OK (I strongly recommend that you give the
> user a way of reviewing, adding, modifying, deleting names). Once
everything
> has been confirmed, your array is ready to go.
>
> You can use the array, not only the combobox, to populate your table.
>
> Find the logic of your table and combine it to your array. You are going
to
> have to figure out the logic behind inserting the text in the appropriate
> places.
>
> Prepare an Autotext that has all the rows/cells neccessary for one person,
> then, before inserting the text, insert as many Autotext as you have
people,
> then either place the cursor, or use the range object to define the table
> you need for the job.
>
> For example:
>
> With MyRange.Tables(1)
>
> For r = 0 To UBound(MyArray, 2) 'Look for UBound in the Help
> .Cell((r * 4) + 1, 2).Range.Text = MyArray(0 , r)
> .Cell((r * 4) + 1, 4).Range.Text = MyArray(1 , r)
> .Cell((r * 4) + 2, 2).Range.Text = MyArray(2 , r)
> .Cell((r * 4) + 2, 4).Range.Text = MyArray(3 , r)
> .Cell((r * 4) + 3, 2).Range.Text = MyArray(4 , r)
> 'etc.
> Next r
>
> End With
>
> Or something like that...
>
> HTH
> Cheers.
> --
> _______________________________________
> Jean-Guy Marcil
> jmarcil@sympatico.ca
>
> "Al & Cay Grant" <bigal_nz@no$spam.remove.hotmail.com> a écrit dans le
> message de news: bm7cj1$8rr$1@lust.ihug.co.nz...
> > Jean-Guy and Jonathon know the background to this question, so if your
> > reading this guys I would love to hear your thoughts.
> >
> > I have a series of listboxes which ask for;
> > Name, Address, Town, DOB, Age, Job.
> >
> > This is then saved as an array, which is used to populate a list box
with
> > the above information.
> >
> > Each ROW in the listbox represents a person, but because of Redim
Preserve
> > affecting only the columns each COLUMN of the array is a person. They
are
> > transposed between the listbox and the array.....
> >
> > I am at the stage now where I am inserting the personal info into a
table
> in
> > a template.
> >
> > The table is the first table in the template and is 4 x 4. If their is
> more
> > than one person additional tables (which contain formatting) are
inserted
> by
> > way of a autotext entry.
> >
> > Now I could insert each bit of personal information bit by bit with
> > something like:
> >
> > For r = 0 To numberinlistbox
> > .Tables(1).Cell((r * 4) + 1, 2).Range.Text = ListBox2.List(r, 0) '
Insert
> > Full Name
> > Next r
> >
> > But that is gonna mean 6 loops, that loop for each person, and typically
> > talking about 2-3 people, and is rather ugly way to do it.
> >
> > I have read on a MVP website that its better to insert as much data as
> > possible at once, and that to do it, peice by peice is very slow.
> >
> > Anybody know a way to do this quicker?
> >
> > The end result should look like:
> >
> > Name1 DOB: 12/12/80
> > Address1 AGE: 23
> > Town1 OCC: Builder
> >
> > Where DOB/AGE/OCC are in the autotext table.....
> > <