• Extracting word table data (Word 97)

    Author
    Topic
    #367803

    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

    Viewing 1 reply thread
    Author
    Replies
    • #574611

      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?

      • #574743

        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(“c:Dataappraisal.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

        • #574820

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

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

          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.

          • #575087

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

            Cheers
            Geof

    • #574616

      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

    Viewing 1 reply thread
    Reply To: Extracting word table data (Word 97)

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: