Visual Basic Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming Languages - MoreVisual Basic Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old December 6th, 2003, 09:04 PM
Rechen Rechen is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2003
Posts: 42 Rechen User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 30 m 27 sec
Reputation Power: 5
mail merge error

Hi,

I am trying to merge the word mail merge with VB6. Sudenly its giving me error in the opendataSource method.

That is its saying that "OpenDataSource property or method is not available because preview mode is active"


Here is my code

Dim app As Word.Application
Dim doc As Word.Document
app = CreateObject("Word.Application")
doc = app.Documents.Add
app.PrintPreview = False
With doc.MailMerge
With .Fields
.Add(app.Selection.Range, "Contact_Name")
app.Selection.TypeParagraph()
.Add(app.Selection.Range, "Address")
End With
Dim autotxt As Word.AutoTextEntry
autotxt = app.NormalTemplate.AutoTextEntries.Add("MyLabelLayout", doc.Content)
doc.Content.Delete()
.MainDocumentType = Word.WdMailMergeMainDocType.wdMailingLabels
.OpenDataSource(Name:="C:\data.txt")
app.MailingLabel.CreateNewDocument(Name:="5160", Address:="", AutoText:="MyLabelLayout")
.Destination = Word.WdMailMergeDestination.wdSendToNewDocument

.Execute()

autotxt.Delete()




Anybody knows anything about this error?

If you know please help me.

Regards
Rechen

Reply With Quote
  #2  
Old December 7th, 2003, 06:03 PM
Emmanuel Emmanuel is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2003
Posts: 4 Emmanuel User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Smile

Hi,



You've already found the solution with the following instruction : app.PrintPreview = False

therefore it's ok with a the correct format for your data.txt source. For example, for its content you can choose ; as separator like this :

Contact_Name;Address
Emmanuel;10 code street vb city



Here's your vb code customized to see what happens :

Dim app As Word.Application
Dim doc As Word.Document
Set app = CreateObject("Word.Application")
app.Visible = True

Set doc = app.Documents.Add
app.PrintPreview = False

With doc.MailMerge

With .Fields
.Add app.selection.Range, "Contact_Name"
app.selection.TypeParagraph
.Add app.selection.Range, "Address"
End With

Dim autotxt As Word.AutoTextEntry
Set autotxt = app.NormalTemplate.AutoTextEntries.Add("MyLabelLayout", doc.content)
doc.content.Delete
.MainDocumentType = Word.WdMailMergeMainDocType.wdMailingLabels
.OpenDataSource Name:="C:\Data.txt"
app.MailingLabel.CreateNewDocument Name:="5160", Address:="", AutoText:="MyLabelLayout"
.Destination = Word.WdMailMergeDestination.wdSendToNewDocument

.Execute

End With
autotxt.Delete

app.Quit

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming Languages - MoreVisual Basic Programming > mail merge error


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 1 hosted by Hostway
Stay green...Green IT