读取access中长二进制文件
数据库file.mdb 表filetab 表中字段:fielid filename filedes filedate为长二进制数据
其中一条为 fielid 7 filename test.xls filedes test.xls filedate长二进制数据
以下代码来自网上。
红字部分如何修改才能读出来并打开
源程序中通过 TreeView 选择后打开。怎样修改为指定打开如 fileid = filename =
'读出来
Private Sub CommandButton1_Click()
Dim tast As String
'至少要引用Microsoft ActiveX Data Objects 2.5 Library
On Error Resume Next
Dim wordFile As String
If x = "" Then
MsgBox "参数错误,不能打开文档!"
Exit Sub
End If
z = LCase(Right(x, 3))
Set conn = CreateObject("ADODB.connection")
conn.Provider = "Microsoft.Jet.OLEDB.4.0"
conn.Open ActiveDocument.Path & "\file.mdb"
Set rs = CreateObject("adodb.recordset")
sql = "select * from filetab where filenae =" & Chr(34) & CStr(x) & Chr(34)
rs.Open sql, conn, adOpenKeyset, adLockOptimistic
tast = ActiveDocument.Path & "\TempTest.tmp"
If Dir(tast) <> "" Then
Kill tast
End If
Set StmWord = New ADODB.Stream
With StmWord
.Mode = adModeReadWrite
.Type = adTypeBinary
.Open
.Write rs!内容
.SaveToFile tast
.Close
End With
rs.Close
Set rs = Nothing
Set conn = Nothing
If z = "doc" Then
EXE = "Winword.exe"
ElseIf z = "xls" Then
EXE = "excel.exe"
Else
EXE = "mspaint.exe"
End If
Call Shell(EXE & Chr(9) & Chr(34) & tast & Chr(34), 1)
If Err <> 0 Then
MsgBox "指定的打开参数有误,不能正确执行打开操作。"
Exit Sub
End If
End Sub