Results 1 to 6 of 6
  1. #1
    3 Star Lounger
    Join Date
    Apr 2001
    Location
    Levin, Manawatu-Wanganui, New Zealand
    Posts
    324
    Thanks
    9
    Thanked 28 Times in 26 Posts

    Extracting word table data (Word 97)

    Good evening
    I am writing a routine that extracts data from a Word table and writes it to an Access database.

    If the data is typed directly into the table in the Word doc all is well.
    However if the table data is selected from a list based on Word Forms combo box the data written to the database is a square. I dont know what this is, could be chr(7) or what ever the end of cell marker is ? How do I find out ?

    I guess the question is ..
    What is the data resulting from a Word Form combo box..?

    Any comments welcome. It would be nice to restrict the the data available to a list.

    Failing this I could populate bookmarks with data from a custom form.
    The data has to rside in the form as well as in the database. !!

    Cheers
    Geof

  2. #2
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts

    Re: Extracting word table data (Word 97)

    Are the checkboxes inside table cells? Maybe the box is a field code; you shouldn't get the end-of-cell (with Selection.Text) unless the cell is empty. Could you post a little sample document?

  3. #3
    Super Moderator
    Join Date
    Dec 2000
    Location
    New York, NY
    Posts
    2,970
    Thanks
    3
    Thanked 29 Times in 27 Posts

    Re: Extracting word table data (Word 97)

    Geof,

    As Jefferson is suggesting, the dropdown form field is a field, so you're not going to be able to return its value the way you would for normal text.

    Assuming you have a form dropdown that is called "DropDown1" in a protected forms document, the following code will return the currently displayed item in the dropdown:

    Public Sub ReturnDropDownResult()
    Dim strDropDownText As String
    strDropDownText = ActiveDocument.FormFields("DropDown1").Result
    MsgBox strDropDownText
    End Sub

    - doesn't matter whether it's in a table or not in this case.

    Gary

  4. #4
    3 Star Lounger
    Join Date
    Apr 2001
    Location
    Levin, Manawatu-Wanganui, New Zealand
    Posts
    324
    Thanks
    9
    Thanked 28 Times in 26 Posts

    Re: Extracting word table data (Word 97)

    Hi Jefferson, Gary
    Thanks for the thoughts.
    I learned that we cant return from a field in the same manner as a selection.
    In the code I am looping thru the target table until an error condition arising from an emty cell occurs. A bit clumsy but it works.
    The max number of iems in the target table will be 4

    My code in module listed under here
    ============
    Option Explicit
    Dim strName As String
    Dim strCourse As String
    Sub RecordToDatabase()
    On Error GoTo errorHandler
    GetName
    GetCourses
    Exit Sub
    errorHandler:
    Select Case Err.Number 'Empty cell
    Case 3315
    Exit Sub
    Case Else
    MsgBox ("Error number " & Err.Number & " occurred " & Err.Description)
    End Select
    End Sub

    Sub GetName()
    Dim myRange As Range
    With ActiveDocument
    Selection.GoTo What:=wdGoToBookmark, Name:="Name"
    End With
    Set myRange = Selection.Range
    myRange.SetRange Start:=myRange.Start, End:=myRange.End

    strName = myRange.Text
    ' includes an end of cell char which I think is chr(7)
    strName = Left(strName, Len(strName) - 2)
    MsgBox (strName)

    End Sub
    Sub GetCourses()
    Dim myRange As Range
    Dim oCell As Object
    Dim strCourse As String
    With ActiveDocument
    Selection.GoTo What:=wdGoToBookmark, Name:="CourseBegin"
    End With
    For Each oCell In Selection.Tables(1).Columns(2).Cells
    Set myRange = oCell.Range
    myRange.SetRange Start:=myRange.Start, End:=myRange.End - 1
    strCourse = myRange.Text
    readintodatabase (strCourse)
    Next oCell

    End Sub

    Sub readintodatabase(strCourse)
    Dim db As database
    Dim rs As recordset
    Set db = OpenDatabase("cataappraisal.mdb")
    Set rs = db.OpenRecordset("tblTrainingItems", dbOpenDynaset)
    With rs
    .AddNew
    !Name = strName
    !Course = strCourse
    .Update
    .Bookmark = .LastModified
    End With
    rs.Close
    db.Close
    End Sub

  5. #5
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts

    Re: Extracting word table data (Word 97)

    Try this to integrate Gary's suggestion as to how to read out the value of the drop down control:

    <pre>For Each oCell In Selection.Tables(1).Columns(2).Cells
    Set myRange = oCell.Range
    <font color=blue>If myRange.FormFields.Count > 0 Then
    strCourse = myRange.FormFields(1).Result
    Else</font color=blue>
    myRange.SetRange Start:=myRange.Start, End:=myRange.End - 1
    strCourse = myRange.Text
    <font color=blue>End If</font color=blue>
    readintodatabase (strCourse)
    Next oCell</pre>

    Obviously this makes the assumption that there will only be one Form Field in the cell and that you want the text of the first one. Otherwise, I don't see any reason to think it wouldn't work.

  6. #6
    3 Star Lounger
    Join Date
    Apr 2001
    Location
    Levin, Manawatu-Wanganui, New Zealand
    Posts
    324
    Thanks
    9
    Thanked 28 Times in 26 Posts

    Re: Extracting word table data (Word 97)

    Jefferson
    Thank you very much for that.
    I will let you know how it worked out.

    Cheers
    Geof

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •