Private Sub Form_Load()
AdoRs.Open "select * from tb_wdlb order by Bh", Cnn, adOpenKeyset
If AdoRs.RecordCount > 0 Then '如果记录集大于零则执行
AdoRs.MoveFirst '移动记录指针
Combo1.AddItem "所有类别" '在Combo1下拉列表框中显示"所有类别"
Do While AdoRs.EOF = False '添加文档类别
Combo1.AddItem AdoRs.Fields("Mc") '将Mc字段中的数据添加在Combo1下拉列表框中
AdoRs.MoveNext '移动记录指针
Loop
End If
AdoRs.Close '关闭数据表
End Sub
Private Sub ListView1_DblClick() '打开查询到的文档
On Error GoTo x
Dim MyWord As Object
Set MyWord = CreateObject("Word.Application") '创建并返回一个对对象引用
MyWord.Documents.Open (App.Path & "\TempFiles\" & ListView1.SelectedItem.SubItems(2))
MyWord.Visible = True
x:
Exit Sub
End Sub
Private Sub DownFile()
Set cn = New ADODB.Connection '重新创建数据源
If Trim(ReadCompturName) = Trim(CompturName) Then
cn.ConnectionString = "Provider=SQLOLEDB.1;Persist Security Info=False;password=yzcj;User ID=sa;Initial Catalog=db_Document;;Data Source =YSF"
Else
cn.ConnectionString = "Provider=SQLOLEDB.1;Persist Security Info=False;User ID=sa;Initial Catalog=db_Document;Data Source = '" & ReadCompturName & "'"
'End If
cn.Open '打开数据库
Set rs = New ADODB.Recordset '重新创建记录集对象
'打开数据表
rs.Open "select * from tb_Document where WDBT='" & Me.ListView1.SelectedItem.SubItems(2) & "'", cn, adOpenStatic, adLockOptimistic
Set DocFiles = New ADODB.Stream '创建流对象
DocFiles.Type = adTypeBinary '类型设置为二进制形式
DocFiles.Open '打开流文件
DocFiles.Write rs.Fields("WDNR").Value '将数据库字段中的信息写入文件中
TempPath = App.Path & "\TempFiles\" & Me.ListView1.SelectedItem.SubItems(2) '文件路径
On Error Resume Next
DocFiles.SaveToFile TempPath, adSaveCreateOverWrite '保存文件,adSaveCreateOverWrite为覆盖以存在文件"
frm_main.WebBrowser1.Navigate TempPath
rs.Close '关闭数据表
cn.Close '关闭数据库
End Sub