Reply
 
Thread Tools Display Modes
  #1   Report Post  
Posted to microsoft.public.word.mailmerge.fields
z
 
Posts: n/a
Default generating Reports using VB.net

hi i want to ask how can we retrieve data from MS sql server table
northwind and generate report of same data in formated form in MS word
using VB.net ... i need its code can any one help please .. its real
urgent .. i m currently using Visual Studio 2003 ... and MS SQL server
2003 thanks in advance...

  #2   Report Post  
Posted to microsoft.public.word.mailmerge.fields
Cindy M -WordMVP-
 
Posts: n/a
Default generating Reports using VB.net

Hi Z,

i want to ask how can we retrieve data from MS sql server table
northwind and generate report of same data in formated form in MS word
using VB.net ... i need its code can any one help please .. its real
urgent .. i m currently using Visual Studio 2003 ... and MS SQL server
2003 thanks in advance...

It's certainly possible, and not even too difficult... if you have the
proper background knowledge. If you haven't, then you're going to need
to dig in, or hire someone with the requisite knowledge.

Basically, you drop the information into bookmarks on the prepared Word
document.

Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update Jun 8 2004)
http://www.word.mvps.org

This reply is posted in the Newsgroup; please post any follow question
or reply in the newsgroup and not by e-mail :-)

  #3   Report Post  
Posted to microsoft.public.word.mailmerge.fields
z
 
Posts: n/a
Default generating Reports using VB.net

Imports Word.ApplicationClass
Imports Excel.ApplicationClass
Imports Microsoft.Office.Core
'Imports Microsoft.Office.Interop
Imports System.IO.Path
Imports Microsoft.VisualBasic
Imports System.Data.SqlClient

Public Class Form1
Inherits System.Windows.Forms.Form

#Region " Windows Form Designer generated code "

Public Sub New()
MyBase.New()

'This call is required by the Windows Form Designer.
InitializeComponent()

'Add any initialization after the InitializeComponent() call

End Sub

'Form overrides dispose to clean up the component list.
Protected Overloads Overrides Sub Dispose(ByVal disposing As
Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub

'Required by the Windows Form Designer
Private components As System.ComponentModel.IContainer

'NOTE: The following procedure is required by the Windows Form
Designer
'It can be modified using the Windows Form Designer.
'Do not modify it using the code editor.
Friend WithEvents Button1 As System.Windows.Forms.Button
System.Diagnostics.DebuggerStepThrough() Private Sub
InitializeComponent()
Me.Button1 = New System.Windows.Forms.Button
Me.SuspendLayout()
'
'Button1
'
Me.Button1.Location = New System.Drawing.Point(24, 24)
Me.Button1.Name = "Button1"
Me.Button1.Size = New System.Drawing.Size(120, 80)
Me.Button1.TabIndex = 0
Me.Button1.Text = "Automate Word"
'
'Form1
'
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
Me.ClientSize = New System.Drawing.Size(168, 133)
Me.Controls.Add(Me.Button1)
Me.Name = "Form1"
Me.Text = "Form1"
Me.ResumeLayout(False)

End Sub

#End Region
Private WithEvents oWord As Word.ApplicationClass
Private WithEvents ThisApplication As Word.Application
Private WithEvents ThisDocument As Word.Application
Private WithEvents WordApp As Word.ApplicationClass
Private WithEvents openFileDialog1 As OpenFileDialog
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
CreateWordTable()
End Sub

Private Sub CreateWordTable()
oWord = CreateObject("Word.Application")
oWord.Visible = False

oWord.Documents.Add()
Dim rng As Word.Range = oWord.ActiveDocument.Range(Start:=0,
End:=0)
rng.InsertBefore("Author's Contact")
rng.Font.Name = "Verdana"
rng.Font.Size = 16
rng.InsertParagraphAfter()
rng.InsertParagraphAfter()
rng.SetRange(rng.End, rng.End)
rng.Tables.Add( _
Range:=oWord.ActiveDocument.Paragraphs(2).Range, _
NumRows:=1, NumColumns:=3)
Dim tbl As Word.Table = oWord.ActiveDocument.Tables(1)
tbl.Range.Font.Size = 12
tbl.Range.Font.Name = "Verdana"
tbl.Borders.InsideLineStyle = _
Word.WdLineStyle.wdLineStyleSingle
tbl.Borders.OutsideLineStyle = _
Word.WdLineStyle.wdLineStyleDouble
tbl.Columns(1).SetWidth( _
oWord.Application.InchesToPoints(1.5), _
Word.WdRulerStyle.wdAdjustNone)
tbl.Columns(2).SetWidth( _
oWord.Application.InchesToPoints(2.25), _
Word.WdRulerStyle.wdAdjustNone)
tbl.Columns(3).SetWidth( _
oWord.Application.InchesToPoints(3.25), _
Word.WdRulerStyle.wdAdjustNone)
tbl.Cell(1, 1).Range.Text = "Author"
tbl.Cell(1, 2).Range.Text = "Contact#"
Dim rngCell As Word.Range = tbl.Cell(1, 3).Range
rngCell.Text = "Address"
rngCell.ParagraphFormat.Alignment = _
Word.WdParagraphAlignment.wdAlignParagraphRight
Dim strSQL As String = _
"SELECT au_lname, phone, address " & _
"FROM authors"

Dim cnn As SqlConnection
Dim sdr As SqlDataReader
Dim cmd As SqlCommand
cnn = New SqlConnection( _
"workstation id='DEV-INTERN';packet size=4096;integrated
security=SSPI;data source='DEV-INTERN';persist security
info=False;initial catalog=pubs")
cnn.Open()
cmd = New SqlCommand(strSQL, cnn)
sdr = cmd.ExecuteReader(CommandBehavior.CloseConnection)
Dim intRow As Integer = 2
While sdr.Read()
tbl.Rows.Add()
tbl.Cell(intRow, 1).Range.Text = sdr(0).ToString
tbl.Cell(intRow, 2).Range.Text = sdr(1).ToString
tbl.Cell(intRow, 3).Range.Text = sdr(2).ToString
intRow += 1
End While
tbl.Rows(1).Range.Bold = 1

oWord.ActiveDocument.SaveAs("C:\Documents and
Settings\zafzal\Desktop\word.doc")
oWord.ActiveDocument.Close()
Close()

End Sub


End Class

Reply
Thread Tools
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Create multiple stacked tables in word using vb.net Jenny Beavers Tables 2 January 17th 06 04:12 PM
Mail Merge events and VB.NET Bill S. Mailmerge 1 August 12th 05 08:48 PM
Word and Excel generating Error reports and shut down automaticall Matt Microsoft Word Help 2 May 20th 05 01:01 AM
I would like to page number 6 seperate reports when completed.Can. Geoff Barrett Page Layout 3 March 22nd 05 06:04 PM
legacy system reports to word Brad Microsoft Word Help 5 December 7th 04 08:50 PM


All times are GMT +1. The time now is 01:54 PM.

Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 Microsoft Office Word Forum - WordBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Word"