我做过word文件存和取从SQL7的,可能是你没有理解!其实并不是直接一个word文件就存放在一个字段中而是应该分别放:关于如何调用word你可以搜索一下,以前的帖子很多!
假如已经有建好的msword (word.application) msdocument(document.application)
一个word文档:关于一个工程,有工程名称:123-345; 工程编号:gh-1234
这个文件应该对应与两个字段(就是存在两个字段中)而且这个word文档要有四个table;一个放“工程名称”,一个放“123-345”,再一个放“工程编号”,最后一个放“gh-1234”,至于这个table显示还是不显示,完全看你怎么设置!
代码:word.document.range.cell(0,1).text="123-345"
这个就是tabel2中包含的数据,然后和数据库连在一起rs!field="123-345"
反之就是读取!
有些代码可能准确性不足,仅供参考!你看一下VBA最好!

解决方案 »

  1.   

    Option Explicit
    Dim RS As New ADODB.Recordset
    Dim Cnn As New ADODB.Connection
    Dim MS_WORD As Object
    Public Sub Insert(TableName As String, MSH As MSHFlexGrid)
    '=============================
    '变量声明
    Dim strCnn As String
    Dim strSQL As String
    Dim msgResult As VbMsgBoxResult
    '=============================strCnn = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source= d:\*mdb ;Persist Security Info=true"
    Err.Clear
    Cnn.Open strCnn
    If Not Err.Number = 0 Then
      msgResult = MsgBox("数据库连接错误!", vbOKOnly, "project")
      Exit Sub
    Else
      strSQL = "select * from " & TableName
            Err.Clear
            RS.Open strSQL, Cnn, adOpenKeyset, adLockOptimistic
            If Not Err.Number = 0 Then
              MsgBox "数据库表连接错误!"
              Exit Sub
            Else
              Screen.MousePointer = 11
              Call InsertTableToWord(MSH)
              Screen.MousePointer = 0
            End If
    End If
    Cnn.Close
    End Sub
    Private Sub InsertTableToWord(MSH As MSHFlexGrid)
    Dim I, J, Col, Row As Integer
    Dim cellContent As String
    On Error GoTo handleErr
    Col = MSH.Cols
    Row = RS.RecordCount
    Set MS_WORD = CreateObject("Word.Basic")
    MS_WORD.FileNewdefault
    MS_WORD.LeftPara
    MS_WORD.ScreenUpdating 0
    MS_WORD.TableInsertTable Col, Row, , , 16
    RS.MoveFirst
    For I = 1 To MSH.Cols - 1
        cellContent = RS.Fields(I - 1).Name
        MS_WORD.Insert cellContent
        MS_WORD.NextCell
    Next I
    Do
       For I = 1 To MSH.Cols - 1
           If IsNull(RS.Fields(I - 1).Value) Then
              cellContent = ""
           Else
              cellContent = RS.Fields(I - 1).Value
           End If
           MS_WORD.Insert cellContent
           MS_WORD.NextCell
       Next I
    RS.MoveNext
    Loop Until RS.EOF = True
    MS_WORD.FileSaveAs "d:\Hello1.Doc"
    MS_WORD.FileClose
    MS_WORD.MsgBox "chenggong"
    Set MS_WORD = Nothing
    Exit Sub
    handleErr:
            Set MS_WORD = Nothing
            MsgBox ("导出失败!")
    End Sub
      

  2.   

    是不是可以应用OLE控件来作为介质传递,而且数据库的数据正好是以WORD形式存在,这是他的基本属性
      

  3.   

    我的想法是,能不能将整个word文档存入access的一个字段里,因为access里有OLE的字段类型。然后在点击菜单时,从access中取出内容,生成一个word对象,并让word显示,在关闭word后,再将word文档存入access.不知这样可行不可行。现在还没有试!
      

  4.   

    这样是不好的,ACCESS会变得很大,不如在ACCESS中只放WORD档所在的位置信息。