Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #1  
Old 02-22-2014, 10:06 AM
marksm33 marksm33 is offline Multiple Userforms Displaying Different Content but Returning Same Content? Windows 7 64bit Multiple Userforms Displaying Different Content but Returning Same Content? Office 2013
Novice
Multiple Userforms Displaying Different Content but Returning Same Content?
 
Join Date: Jan 2014
Posts: 12
marksm33 is on a distinguished road
Smile Multiple Userforms Displaying Different Content but Returning Same Content?

I believe I have 98% of this project completed. I have 2 MS Word Documents. One stores source tables, the other (the Main Document) is the document that the user interacts with. On the Main Document there are multiple macrobuttons. Each of these macrobuttons leads to a separate Userform. The userforms pull data from the tables on the second document. The user then selects data from the userform to insert into the Main Document at prescribed bookmarks that are delineated in the commandbutton code. Everything up until this point works PERFECTLY. However, no matter which userform the user selects information from, even though the userforms DISPLAY the correct data from different columns in the tables on the source document, the commandbutton inserts data ONLY FROM THE FIRST COLUMN of the FIRST TABLE. I feel like I am missing a very small but important step. I feel like the code is incorrect either in the individual Userforms or the Commandbuttons, but I'll be darned if I can understand where. I just need to know how to fix the problem, I can take it from there. I use MS Word 2010 with Windows 7.





Here is the code that I am using in the Userforms. I BELIEVE the problem is located somewhere in the underlined portion where it is generating an array.

Code:
Private Sub Userform_Initialize()

Dim oDoc As Word.Document
Dim oTbl As Word.Table
Dim arrTableData() As String
Dim lngRows As Long, lngCols As Long
Dim strSQL As String

Dim arrData() As String
Dim sourcedoc As Document
Dim i As Integer
Dim j As Integer
Dim myitem As Range
Dim m As Long
Dim n As Long

  'Load Lb2br using an external Word document.  Data is defined in a document table.
    'Open the document not visible to the user.
    Set oDoc = Documents.Open(ThisDocument.Path & "\Word Table Data Source.docm", , , , , , , , , , , False)
    Set oTbl = oDoc.Tables(2)
    
    'Get the number of list members (i.e., table rows - 1 if header row is used)
  i = oDoc.Tables(2).Rows.Count - 1
  'Get the number of list member attritbutes (i.e., table columns)
  j = oDoc.Tables(2).Columns.Count
  'Set the number of columns in the Listbox
  lb2br.ColumnCount = j
  'Load list members into an array
  ReDim arrData(i - 1, j - 1)
  For n = 0 To j - 1
    For m = 0 To i - 1
      Set myitem = oDoc.Tables(2).Cell(m + 2, n + 1).Range
      myitem.End = myitem.End - 1
      arrData(m, n) = myitem.Text
    Next m
  Next n
 

    'Use the .ColumnWidth property to set column widths.  0 results in a hidden column.
  lb2br.ColumnWidths = "0;800;0;0;0"
  
    'Use the .AddItem method to add a multi-column row for each array element.
    lb2br.AddItem

    
    
    'Dimesion a data array to collect contents. Note: .Row.Count - 2 is used to exclude the table heading row.
    ReDim arrTableData(oTbl.Rows.Count - 2, oTbl.Columns.Count - 1)
    'Strip end of cell marker and data from each row/column (cell) to array
    For lngRows = 2 To oTbl.Rows.Count
      For lngCols = 1 To oTbl.Columns.Count
        arrTableData(lngRows - 2, lngCols - 1) = Left(oTbl.Cell(lngRows, lngCols).Range.Text, _
                                                 Len(oTbl.Cell(lngRows, lngCols).Range.Text) - 2)
      Next lngCols
    Next lngRows
    'Populate ListBox with array data using the List method.
    lb2br.List = arrTableData

Reply With Quote
 

Tags
multiple userforms



Similar Threads
Thread Thread Starter Forum Replies Last Post
Multiple Userforms Displaying Different Content but Returning Same Content? Allow Multiple Content Control same cell of form table DeborahBartlett Word 1 01-04-2014 11:06 AM
Multiple Userforms Displaying Different Content but Returning Same Content? Deleting a table from a content control -- preserving the content control BrainSlugs83 Word Tables 8 11-14-2013 03:06 AM
Multiple Userforms Displaying Different Content but Returning Same Content? Content Controls Sammie0Sue Word 6 11-06-2013 10:56 PM
Multiple Userforms Displaying Different Content but Returning Same Content? macro for change content of cell2 when content of cell1 changes Intruder Excel Programming 1 11-17-2012 08:24 PM
Package for CD with links to Windows media player content and Flash Shockwave content hectorh PowerPoint 4 10-15-2009 12:22 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 03:23 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft