Private Sub Command1_Click()
Dim stm As ADODB.Stream
Dim rs As ADODB.Recordset
Dim rs2 As ADODB.Recordset
Dim rs3 As ADODB.Recordset
Dim objWord As Word.Application
Dim VBC As String
Dim SQL As String
Dim SQL2 As String
Dim SQL3 As String
Dim x As Long
Set objWord = New Word.Application
Call Open_Connection
SQL = "SELECT DocumentDetailID FROM DocumentDetail"
Set rs = New ADODB.Recordset
rs.Open SQL, con, adOpenKeyset, adLockOptimistic
Set stm = New ADODB.Stream
stm.Type = adTypeBinary
stm.Open
For x = 1 To rs.RecordCount
SQL3 = "SELECT DocumentDetailID, DocumentID, FinalDocument FROM DocumentDetail " & _
"WHERE DocumentDetailID = " & rs.Fields("DocumentDetailID")
Set rs3 = New ADODB.Recordset
rs3.Open SQL3, con, adOpenKeyset, adLockOptimistic
With stm
.Write rs3.Fields("FinalDocument").Value
.SaveToFile App.Path & "\Temp.doc", adSaveCreateOverWrite
End With
objWord.Documents.Open App.Path & "\Temp.doc"
VBC = objWord.ActiveDocument.ComputeStatistics(wdStatisticCharacters)
SQL2 = "INSERT INTO VBCTable (DocumentDetailID, DocumentID, VBC) VALUES ('" & rs3.Fields("DocumentDetailID").Value & "', '" & rs3.Fields("DocumentID").Value & "', '" & VBC & "')"
Set rs2 = con.Execute(SQL2)
Set rs2 = Nothing
objWord.ActiveDocument.Close False
Set rs3 = Nothing
Label1.Caption = x & " of " & rs.RecordCount
toMoveNext:
rs.MoveNext
Next
objWord.Quit
rs.Close
Set rs = Nothing
con.Close
End Sub
Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.
When asked, what has been your best career decision?
Deciding to stick with EE.
Being involved with EE helped me to grow personally and professionally.
Connect with Certified Experts to gain insight and support on specific technology challenges including:
We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE