Welcome to WebmasterWorld Guest from 184.108.40.206
Forum Moderators: ocean10000
The web site collects client contact details including mailing address and I want to output that on a local printer onto printing label. The web site is hosted remotely so I canít access the database directly but I was thinking about a web service of some type. Ideally I would search the database by criteria and print off labels as appropriate.
Anybody know if you can run a word mail merge using a web service as a data source?
Anybody got any better ideas?
For word 2K I use find and replace on a standard label template from VBScript in HTML. For word 2002/XP mailmerge over OLEDB works fine.
One big problem is sending a record id parameter to word when automating it, in theory it can be done with the Run command, but its buggy. So for Word2K I code client side vbscript with actual text values, after calling the database query
Just to get this straight in my mind when you talk about a mail merge with OLEDB are you suggesting you create a VB application that accepts the web service data and then passes that data to an underlying database with which you can then mail merge?
Or are you suggesting you can somehow create an OLEDB data connection to the web service (please excuse my ignorance if this is a silly question!)
If your database is not reachable then you need to connect to a webservice on the webserver, I havent done such in Work2K or XP but Word03, WordProcessingML seems to be able to do this.
The other way is to connect to the data source via ASP, & create a clientside vbscript with actual data, then automate word on the client with a pre-defined template and populate it using find and replace
Actually, I find the latter, VBScript methods much faster for a single page of labels because all the automation and address formatting is done before making the word application visible.
I just created some label maker pages a couple of months ago. Here's how:
Top of the ASP page:
Response.ContentType = "application/msword"
Response.AddHeader "Content-Disposition", "attachment; filename=LabelExport.doc"
Use a SQL query or web service to retrieve your name/address results.
Here's my CSS style. Notice the "@page"
margin: .10in .15in .0in .15in;
Output code enclosed inside of a div
response.Write "<div class=""Section1"">"
Output a page break after each label
response.Write "<br clear=all style='page-break-before:always'>"
Let me know if you need all the code - I'd be happy to email it to you.
I've got no problem grabbing the address details from the database and sticking in them on the page using a repeater or something similar.
I assume I can ignore the barcode bit and that the second section just defines the font used on each label.
I assume that @page Section1 defines the page size (label size) with margins etc and then the div.Section1 assigns the page size to the content of each div?
Presumably you have a number of columns/rows to match the number of labels on the sheet?
Have you ever tried this sort of approach with a label printer rather than sticking sheets through a conventional printer? I assume this would be easier still as you donít have to worry about which label you are starting on?
Thanks for all the comments.
This piece of code is, in fact, only for a label printer setup. The "<br clear=all style='page-break-before:always'>" piece of the code will actually cause a page break when printing the document. To use this piece of code with a normal printer of label stickies, you'd have to leave the <br> out and use more <tr><td> spacing...
I tried the MS Word route - did the merge, saved as an MTH file and examined the code. I thought I would prepare a file that way, but what a mess!
So instead I prepared a TXT document which was downloaded to the users desktop, which they can use to merge their own in Word or Works, etc. Even works on the Mac.
And with the Mozilla printing bug, several of my users couldn't print labels past the first page, so this will help them. Plus I don't have to worry about web formating the labels any more.
I created a ".lbl" file (which forces the download instead of txt) and let them do the Mail Merge into labels.
The next step would be to write a VBA in Word that would read that file automatically and avoid all the steps involved.
Anyone know how to do that?
Set objXML = CreateObject("Microsoft.XMLHTTP")
Set objFile = CreateObject("Scripting.FileSystemObject")
objXML.Open "GET", "http:<public address>/RemoteMergeFile.txt", False
strMergeData = objXML.responseText
strMergeFile = "\\<local address>\My Data Sources\LocalMergeFile.txt"
Set objTextStream = objFile.OpenTextFile(strMergeFile, 2, True)
.OpenDataSource Name:= strMergeFile