Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.word.mailmerge.fields
RC RC is offline
external usenet poster
Posts: 22
Default word 2003 automation "unable to open datasource" Stored Pro

I am trying to work with the word object model via .Net and have managed with
some success in setting a mail merge using SQL Sever successfully, I am now
receiving unable to open data source, although when I use word directly using
the ODC file, and view I have created I have success, secondly whilst
exploring the functionality I have tried use calls to stored procedures in
the SQL and whilst the connection seems to be established the only merge
fields that get populated are the number fields, if anyone can shed some
light on the limitations correct method of doing this it would be much
appreciated, in particular I would prefer not to use an ODC file but it
appears to be the only option and would really like to call a stored proc.
any eamples would be great.

In anticipation thanks for your help

r.Report.SQL= "SELECT * FROM ""FullfillTemp"""

it dosnt make much difference if I add some where clause allthough I would
like to change to "exec storedProc p1,p2 etc". and why do you need so many

r.Report.DBodcConnection= a valid ODC file

r.Report.DSNConnection = a valid connection string

Code BlockDim wrdSelection As Word.Selection

Dim wrdMailMerge As Word.MailMerge

Dim wrdMergeFields As Word.MailMergeFields


' Create an instance of Word and make it visible.

wrdApp = CreateObject("Word.Application")

wrdApp.Visible = True

wrdApp.ActivePrinter = printerName

' Add a new document.

wrdDoc = wrdApp.Documents.Add(r.Report.WordDocTemplate)


wrdMailMerge = wrdDoc.MailMerge()

'' Create MailMerge Data file.


Dim mmd As Word.MailMergeDataSource

mmd = wrdMailMerge.DataSource

wrdMailMerge.OpenDataSource(Name:=r.Report.DBodcCo nnection,
Connection:=r.Report.DSNConnection, SQLStatement:=r.Report.SQL)

With wrdMailMerge.DataSource

..FirstRecord = Word.WdMailMergeDefaultRecord.wdDefaultFirstRecord

..LastRecord = Word.WdMailMergeDefaultRecord.wdDefaultLastRecord

End With

' Perform mail merge.

If Preview = False Then

wrdMailMerge.Destination = Word.WdMailMergeDestination.wdSendToPrinter


wrdMailMerge.Destination = Word.WdMailMergeDestination.wdSendToNewDocument

wrdApp.Visible = True

End If

wrdMailMerge.SuppressBlankLines = True


' Close the original form document.

wrdDoc.Saved = True

'' Clean up temp file.


Catch ex As Exception

Me.Cursor = Cursors.Default




'Close the main document


Catch ex As Exception

'dosnt matter if this falls through

End Try

' Release References.

wrdSelection = Nothing

wrdMailMerge = Nothing

wrdMergeFields = Nothing

wrdDoc = Nothing

wrdApp = Nothing

Me.Cursor = Cursors.Default

End Try

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
Excel merge into Word:"unable to open data source" STEVE Microsoft Word Help 3 September 21st 07 02:58 PM
How can I open an "openoffice" ".odt" file in Word 2003 Alex New Users 5 February 5th 07 12:48 PM
You receive a "Word was unable to read this document. It may be corrupt" error message when you open a document in Word 2003 Paul_pixel Microsoft Word Help 1 October 7th 06 06:27 PM
You receive a "Word was unable to read this document. It may be corrupt" error message when you open a document in Word 2003 [email protected] Microsoft Word Help 1 September 5th 06 09:58 PM
Docs stored on server no longer prompting for "open as read only." c0t0d0s0 Microsoft Word Help 2 September 1st 06 02:45 PM

All times are GMT +1. The time now is 03:49 PM.

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

About Us

"It's about Microsoft Word"