Solved

Mail Merger, SQL , Asp.Net VB

Posted on 2010-11-14
18
473 Views
Last Modified: 2012-05-10
am new to Mail Merge.

I have to build a mail merge application in ASP.net VB.
The end user will update a Mail merger document template, then the other end users can able to merge the database values with the uploaded document and can download the new merged doocument with data.

any help or link ?
0
Comment
Question by:Jini Jose
18 Comments
 
LVL 7

Expert Comment

by:mr_nadger
ID: 34135387
Which type of document are you trying to create a template for and how will it be mailed out? (or is it just to create a word doc which can be saved manually to the user's drive?)

We have something where a user provides a Word template, and other users can create saveable/printable documents with fields dragged into from the database. Is that what you're after?
0
 
LVL 7

Accepted Solution

by:
mr_nadger earned 334 total points
ID: 34135460
here's the relevant part of our code, the Office 2003 dll's had to be installed on the web server first.
Dim oMissing As Object = System.Reflection.Missing.Value

            Dim oEndOfDoc As Object = "\endofdoc"



            'Start Word and create a new document.

            Dim oWord As Word._Application

            Dim oDoc As Word._Document

            oWord = New Word.Application()

            oWord.Visible = False

            Dim oTrue As Object = True



            Dim oTemplate As Object = "C:\Enablement.dot"

            oDoc = oWord.Documents.Add(oTemplate, oMissing, oMissing, oMissing)



            Dim oBookMark As Object = "Ref"

            oDoc.Bookmarks.Item(oBookMark).Range.Text = RefID



            Dim oBookMark1 As Object = "DateToday"

            oDoc.Bookmarks.Item(oBookMark1).Range.Text = ATPIssue.ToString



            Dim oBookMark2 As Object = "SHAapp"

            oDoc.Bookmarks.Item(oBookMark2).Range.Text = SHAApproval



            Dim oBookMark3 As Object = "ProductType"

            oDoc.Bookmarks.Item(oBookMark3).Range.Text = Product



            ' Save the document

            Dim newfileguid As Guid = Guid.NewGuid()

            Dim strnewFileName As String = newfileguid.ToString

            'objSubmission.Title) + ".doc";

            'Dim newFilename As Object = "C:\" & newfileguid & ".doc"



            Dim docfilename As String = "CertID" & ".doc"



            Dim newFilename As Object = "\\mypath\" & docfilename



            oDoc.SaveAs(newFilename, oMissing, oMissing, oMissing, oMissing, oMissing, _

             oMissing, oMissing, oMissing, oMissing, oMissing, oMissing, _

             oMissing, oMissing, oMissing, oMissing)



            oDoc.Close(oTrue, oMissing, oMissing)

            oWord.Quit(oTrue, oMissing, oMissing)

            

           'Read and  Save to Database...

            Dim fs As New FileStream(newFilename.ToString(), FileMode.Open, FileAccess.Read)

            Dim fileData As Byte() = New Byte(fs.Length - 1) {}

            fs.Read(fileData, 0, System.Convert.ToInt32(fs.Length))

            fs.Close()



            Response.AddHeader("Content-disposition", "attachment; filename=" & docfilename)

            'Response.AddHeader("attachment; filename=" & Convert.ToString(newFilename))

            Response.ContentType = "application/vnd.ms-word"

            Response.BinaryWrite(fileData)

Open in new window

0
 
LVL 10

Author Comment

by:Jini Jose
ID: 34135469
@mr_nadger

any user can upload a Mail Merge Template. that user or any other user in that company can then select that template. Then the user need to search for the records. after finding the records the user can merge the selected records to the selected mail merge document. The user then download the merged document.
0
 
LVL 10

Author Comment

by:Jini Jose
ID: 34135483
the selected records may have hundreds of records. each records should appear in seperate page of the new document.
In your provided example is it possible ?
0
 
LVL 7

Expert Comment

by:mr_nadger
ID: 34135488
ok, that sounds a little more complicated in that you'd need to have the code for uploading the template be able to map the merge fields to the database table's columns, then you should be able to handle the fields iteratively when it comes to printing them.
0
 
LVL 7

Expert Comment

by:mr_nadger
ID: 34135501
it really depends on what you're trying to deliver in the document, if it's large amounts of data, reporting services may be a better option for you
0
 
LVL 10

Author Comment

by:Jini Jose
ID: 34135519
it is just printing some address labels. The option is user can upload their desired format.
and for mapping the database fields are limited. Just like name, address, phone, postal code etc..
0
 
LVL 7

Expert Comment

by:mr_nadger
ID: 34135554
if the template has the page breaks set up correctly and the printer is loaded with labels, this should work fine; the formatting should be handled by the template rather than the data you're inserting.
0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 10

Author Comment

by:Jini Jose
ID: 34135570
so the recordset having 10 records and if I use your code, it will generate 10 pages ?
0
 
LVL 7

Assisted Solution

by:mr_nadger
mr_nadger earned 334 total points
ID: 34135664
the code given just creates a template for a single record, as it was designed for printing certificates for suppliers.

How are you creating the recordsets for each batch of labels? Could you explain the whole process and usage of your site please, if I know how someone is selecting a template and the recipients they want to mail, I might be able to give you a better response.
0
 
LVL 7

Expert Comment

by:mr_nadger
ID: 34135672
forgot to ask, when is the print run supposed to happen? Will the user just print them as required, or will the labels be queued/scheduled on a central printer?
0
 
LVL 10

Author Comment

by:Jini Jose
ID: 34135695
the user wants to take print out the whole address of the employees. but the format for the output is different depending upon the requirement.
so the user can upload a mail merge template.
then he search for the corresponding records. for eg:- the employees who resides in India.
then he select the available template to merge the data.
after that he click the generate then the system will generate the merged document.
and then show a link to download the merged document.

for eg; the user uploads the template with the following information, Name, Address , Postal code
then he search for the records. suppose he get 100 records.
then he select the template and click merge.
so the out put document should have 100 pages or 25 pages with 4 records each in a page. that depends upon the uploaded mail merge documenet.
0
 
LVL 10

Author Comment

by:Jini Jose
ID: 34135705
"forgot to ask, when is the print run supposed to happen? Will the user just print them as required, or will the labels be queued/scheduled on a central printer?"

when the user clicks on "merge document" or "print label" the system generates the document and will show the download option.
0
 
LVL 7

Expert Comment

by:mr_nadger
ID: 34135860
ok, so you're building a result set on the ASP page, with results present in a gridview or similar object, then some selection method for the labels (dropdown list or radiobutton list etc)...

Let me have a think on this one, I'll need to check the coding for templates as the label templates allow lists to be referenced.
0
 
LVL 23

Assisted Solution

by:Racim BOUDJAKDJI
Racim BOUDJAKDJI earned 166 total points
ID: 34139325
Personally, for simple mail merges, I don't bother using VB but I do it directly from SQL Server who can do mail merges failry easily
0
 
LVL 10

Author Comment

by:Jini Jose
ID: 34197709
hi all

thanks for your help

lastly i developed the code. once i got the time to write an article i will post it in detail.
0
 
LVL 29

Expert Comment

by:Kumaraswamy R
ID: 34391538
This question has been classified as abandoned and is being closed as part of the Cleanup Program.  See my comment at the end of the question for more details.
0

Featured Post

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

Introduction This tutorial provides instructions on how to properly format your Word document using the inbuilt tools provided. The benefits of using these tools means your documents are more accessible and easily portable to other applications an…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Using examples as well as descriptions, and references to Books Online, show the different Recovery Models available in SQL Server and explain, as well as show how full, differential and transaction log backups are performed
Learn how to create and modify your own paragraph styles in Microsoft Word. This can be helpful when wanting to make consistently referenced styles throughout a document or template.

760 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now