by KKLakhanpal (2 Submissions)
Category: Miscellaneous
Compatability: VB 6.0
Difficulty: Unknown Difficulty
Originally Published: Thu 11th December 2003
Date Added: Mon 8th February 2021
Rating:
(1 Votes)
To send data from database in MSWORD file as a string using reference of Microsoft word 8.0 object library
API Declarations
Dim Leng1 As Integer
Dim rs As New ADODB.Recordset
Dim thisdoc As Document
Dim thisrange As Range
Dim wordapp As Word.Application
cnn.Open
rs.Open "select * from quessel order by marks", cnn, adOpenDynamic, adLockBatchOptimistic
If rs.BOF Then
MsgBox "No Record Exists,First Insert a Record", vbOKOnly, "Message"
Else
Set wordapp1 = CreateObject("Word.Application")
Set thisdoc1 = wordapp1.Documents.Add
Set thisrange1 = thisdoc1.Paragraphs(1).Range
thisrange1.Font.Size = 12
thisrange1.Font.Bold = False
thisrange1.ParagraphFormat.Alignment = wdAlignParagraphLeft
thisrange1.InsertAfter "Paper" & vbCrLf
thisrange1.InsertAfter "CLASS :-" & rs("class") & vbCrLf
thisrange1.InsertAfter "SUBJECT :-" & rs("subject") & vbCrLf
thisrange1.InsertAfter "CODE :-" & rs("code") & vbCrLf & vbCrLf & vbCrLf
thisrange1.InsertAfter "Time Allowed :- " & rs("Time") & Space(50) & "Maximum Marks :-" & rs("maxmarks") & vbCrLf & vbCrLf
thisrange1.InsertAfter wordinp & vbCrLf
wordinp1 = ""
coun1 = 1
rs.MoveFirst
While Not rs.EOF
wordinp1 = ""
If IsNull(rs(0)) Then
wordinp1 = wordinp1 + Space(10)
Else
wordinp1 = wordinp1 + Space(10) + rs(0)
End If
If IsNull(rs(1)) Then
wordinp1 = wordinp1 + Space(10)
Else
wordinp1 = wordinp1 + Space(10) + Str(rs(1))
End If
wordinp1 = Str(coun1) + wordinp1
thisrange1.InsertAfter wordinp1 & vbCrLf
coun1 = coun1 + 1
rs.MoveNext
Wend
End If
thisdoc1.SaveAs "c:\worddata.doc"
wordapp1.Quit
MsgBox "Question Paper Report Saved" & vbCrLf & "May Need Formatting in Document", vbOKOnly, "Successfully Saved"
rs.Close
No comments have been posted about To send data from database in MSWORD file as a string using reference of Microsoft word 8.0 object . Why not be the first to post a comment about To send data from database in MSWORD file as a string using reference of Microsoft word 8.0 object .