Using Msword 8.0 Library to send data from MSSQLServer to a word file
Using Msword 8.0 Library to send data from MSSQLServer to a word file
API Declarations
Dim thisrange As Range
Dim wordapp As Word.Application
Dim rs As New ADODB.Recordset
dim cnn as new adodb.connection
Rate Using Msword 8.0 Library to send data from MSSQLServer to a word file
(1(1 Vote))
cnn.ConnectionString = "Provider=SQLOLEDB.1;Persist Security Info=False;User ID=user1;Initial Catalog=pubs;Data Source=NTSERVER"
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:\abc.doc"
wordapp1.Quit
MsgBox "Question Paper Report Saved" & vbCrLf & "May Need Formatting in Document", vbOKOnly, "Successfully Saved"
rs.Close
Using Msword 8.0 Library to send data from MSSQLServer to a word file Comments
No comments yet — be the first to post one!
Post a Comment