DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 4 of 4

Thread: Need help on

Threaded View

  1. #1
    Join Date
    Aug 2011

    Unhappy Word Automation Help using VB

    Hi Guys,
    I need some help on VB console app, and iam new to VB. Here we go, the project , I have a word template, where iam gonna perform a mail merge and send it to the printer. This merge process have to created like a batch or exe file, which will be scheduled to run accordingly. So i started creating a console app using VB. This console should connect to the SQL database and produce me some filtered rows based upon my SQL query. Now i need to create an array for the data rows which i received from the SQL query and save it as a excel or odc format. So that i can use this excel or odc file as my word template data source for mail merge.

    Following is the code i did so far to retrieve the data rows from my SQL query.
    Imports System.Data.SqlClient
    Imports System.Console
    Imports System.NullReferenceException
    Imports Microsoft.Office.Interop
    Imports System
    Imports System.Data
    Module Module1
        Sub Main()
            Dim sConnectionString As String = "Server= ServerName; Database = DbName;" & "Integrated Security = SSPI"
            Dim Connection As New SqlConnection()
            Connection.ConnectionString = sConnectionString
     Dim Dastudent As New SqlDataAdapter("SELECT student.last_name, student.first_name, student.ssn, student.address1_line1, student.address1_line2, student.city1, student.state1, student.zip_code1, student.Graduation_date, awarddata.status_code FROM student INNER JOIN awarddata ON student.person_id = awarddata.person_id WHERE (awarddata.status_code = 'O') and (student.Graduation_date >= '2010/05/01') order by first_name", sConnectionString)
            Dim Dsstudent As New DataSet("Student")
            Dastudent.FillSchema(Dsstudent, SchemaType.Source, "Student")
            Dastudent.Fill(Dsstudent, "Student")
            Dim tblstudent As DataTable
            tblstudent = Dsstudent.Tables("Student")
            Dim drCurrent As DataRow
            For Each drCurrent In tblstudent.Rows
                Console.WriteLine("{0} {1} {2} {3} {4} {5} {6} {7} {8}", _
                    drCurrent("first_name").ToString, _
                    drCurrent("last_name").ToString, _
                    drCurrent("ssn").ToString, _
                    drCurrent("address1_line1").ToString, _
                    drCurrent("address1_line2").ToString, _
                    drCurrent("state1").ToString, _
                    drCurrent("city1").ToString, _
                    drCurrent("zip_code1").ToString, _
        End Sub
    End Module
    As a result it displays all the data row on the exe. I want the the displayed list to be saved in a excel format , so that i can use the excel as my word recipient list and populate the word template and send it to printer.

    The flow looks like touching my nose keeping a fat girl in the middle. but thats the best i came up with.

    Iam using mail merge because , iam generating form letters to be populated. So for sure, i will apreciate if anyone can help me.

    You guys rok..
    Last edited by momsaidnogf; 08-17-2011 at 03:00 PM. Reason: no one helped

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center
Latest Articles
Questions? Contact us.
Web Development
Latest Tips
Open Source

   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center