Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / November 2005

Tip: Looking for answers? Try searching our database.

Stuck on row one when populating a table from data

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Linda - 31 Oct 2005 22:42 GMT
I thought that this was pretty straightforward code but I cannot get
off of row one.

When I execute this bit I end up with a table with one row of data and
it is the last row from the dataset pulled. It overwrites the header
row and every other recordset of information that the SQL statement
pulls. If I take the loop out, I get just the first row of data as you
would expect. There are no errors. Just poor results LOL.

Can someone spot why I am not getting additional rows?  There should be
4 including the header.

With vRecordSet
       If Not .EOF Then

           .MoveFirst
           rowcount = 1
           Set objTable = ActiveDocument.Tables(1)
           objTable.Cell(rowcount, 1).Range.Text = "Resolution #"
           objTable.Cell(rowcount, 2).Range.Text = "Topic"
           objTable.Cell(rowcount, 3).Range.Text = "Department"

           Do While Not .EOF

               rowcount = rowcount + 1
               vResolutionNumber = vRecordSet("resolutionNumber")
               vTopic = vRecordSet("topic")
               vDepartment = vRecordSet("department")

               objTable.Cell(rowcount, 1).Range.Text =
vResolutionNumber
               objTable.Cell(rowcount, 2).Range.Text = vTopic
               objTable.Cell(rowcount, 3).Range.Text = vDepartment

              'Go to next record, exit after last
              vRecordSet.MoveNext
          Loop

          Set objTable = Nothing

       Else
       'if you ARE *else* (are .EOF), that means no record was
matched, tell the user
           MsgBox "No possible match was found."
       End If

   End With

********************************************************
I have tried a number of ways to insert rows but the following code
which seems like it should work, claims that part or all of the 2nd
line is not in reference to a table.

               objTable.Rows(rowcount).Select
               Selection.InsertRowsBelow
Doug Robbins - Word MVP - 01 Nov 2005 12:49 GMT
Use:

With vRecordSet
       If Not .EOF Then

           .MoveFirst
           Set objTable = ActiveDocument.Tables(1)
           objTable.Cell(1, 1).Range.Text = "Resolution #"
           objTable.Cell(1, 2).Range.Text = "Topic"
           objTable.Cell(1, 3).Range.Text = "Department"

           Do While Not .EOF

               ObjTable.Rows.Add
               vRow=ObjTable.Rows.Count
               vResolutionNumber = vRecordSet("resolutionNumber")
               vTopic = vRecordSet("topic")
               vDepartment = vRecordSet("department")

               objTable.Cell(vRow, 1).Range.Text =
vResolutionNumber
               objTable.Cell(vRow, 2).Range.Text = vTopic
               objTable.Cell(vRow, 3).Range.Text = vDepartment

              'Go to next record, exit after last
              vRecordSet.MoveNext
          Loop

          Set objTable = Nothing

       Else
       'if you ARE *else* (are .EOF), that means no record was
matched, tell the user
           MsgBox "No possible match was found."
       End If

   End With

Signature

Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP

>I thought that this was pretty straightforward code but I cannot get
> off of row one.
[quoted text clipped - 51 lines]
>                objTable.Rows(rowcount).Select
>                Selection.InsertRowsBelow
Linda - 01 Nov 2005 14:11 GMT
Thank you.  I tried that and now it is throwing an error saying I
cannot edit that region because document protection is in effect.  It
is my understanding that you need to lock the document to make the form
fields work.  is this what it is talking about or is there something
(obviously) that I am missing?
Doug Robbins - Word MVP - 03 Nov 2005 06:56 GMT
Sounds like the document is protected for forms.

At the beginning of the code insert

ActiveDocument.Unprotect

and at the end add

ActiveDocument.Protect wdAllowOnlyFormFields, NoReset

Signature

Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP

> Thank you.  I tried that and now it is throwing an error saying I
> cannot edit that region because document protection is in effect.  It
> is my understanding that you need to lock the document to make the form
> fields work.  is this what it is talking about or is there something
> (obviously) that I am missing?
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.