How to passing paramter from dw to word

Posted on 2006-07-11
Last Modified: 2013-12-26
hai expert,

l already open word in PB (use OLE object)  but l no idea how to passing value from dw to word.
l has tried coding vb but it's not work.

 below is my coding :

   ole_application = CREATE OLEObject
   //Open Word
    li_ret = ole_application.ConnectToObject("","word.application")
    IF li_ret <> 0 THEN
     // Didn't work lets try it and connect to it
    li_ret = ole_application.ConnectToNewObject("word.application")
  END if
   if(li_ret <> 0) THEN
       MessageBox("", "Error! Cannot open Microsoft Office.", StopSign!)
   //Start open file
    ole_application.Visible = True
   // --- I put my VB coding this here -----

   Destroy ole_application
end if
Question by:firza

Accepted Solution

michaelstoffel earned 500 total points
ID: 17083381
We use iOLEWord.Selection.TypeText(as_text)  It's been around for awhile, so may be outdated but works from Word 97 to 2003

LVL 18

Expert Comment

ID: 17097021

This code opens an existing word document(customer.doc)...
customer.doc has text with bookmarks on it...

This is how it is...
Customer Id:<bookmark here>
First Name: <bookmark here>
Last Name: <bookmark here>
Address: <bookmark here>
City: <bookmark here>
State: <bookmark here>
Phone: <bookmark here>
Zip: <bookmark here>

Now i have a datawindow dw_1 whose sql is...
           "CUSTOMER"."FNAME" ,
           "CUSTOMER"."LNAME" ,
           "CUSTOMER"."ADDRESS" ,
           "CUSTOMER"."CITY" ,
           "CUSTOMER"."STATE" ,
           "CUSTOMER"."ZIP" ,
           "CUSTOMER"."PHONE" ,
        FROM "CUSTOMER"  

ok... in this example what im trying is looking for bookmarks in the word document and inserting data from the DW to it...

//Code to set Data to Word based on Bookmarks
OleObject lole_OLE
Long ll_Col, ll_Cols
String ls_Columns[8]={'id', 'fname', 'lname', &
     'address', 'city', 'state', 'zip', 'phone'}
String ls_name

lole_OLE = CREATE OleObject

SetPointer( HourGlass! )

// Connect to the word application
lole_OLE.ConnectToNewObject( 'word.application' )

lole_OLE.visible = 1 // make visible

// Add each column and then the data items as a bookmark
ll_Cols = UpperBound( ls_Columns )
FOR ll_col = 1 TO ll_Cols
                //Check if bookmark exists...
      IF lole_OLE.ActiveDocument.Bookmarks.Exists( ls_Columns[ ll_Col ]  ) THEN
            lole_OLE.Selection.Goto(TRUE,0,0,ls_Columns[ ll_Col ] )  //Goto the Bookmark
            MessageBox('Error','Bookmark not defined.')
      End IF      

   lole_OLE.Selection.TypeText( String(GetItemAny( dw_1, 1, ls_Columns[ ll_Col ] ) ) ) //inert value from DW

ls_name = 'C:\Customer-' + String(GetItemAny( dw_1, 1, ls_Columns[1 ] ) ) + '.doc'
lole_OLE.ActiveDocument.SaveAs(ls_name) //Save As document with new name...

Hope u get hints from this code...


Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Mavenproject with NetBeans 3 95
HTML-Kit Question 5 96
Notepad++ Remote File Management 3 81
Visual Studio - Accept Button gets border 3 76
Programmer's Notepad is, one of the best free text editing tools available, simply because the developers appear to have second-guessed every weird problem or issue a programmer is likely to run into. One of these problems is selecting and deleti…
How to install Selenium IDE and loops for quick automated testing. Get Selenium IDE from Go to that link and select download selenium in the right hand columnThat will then direct you to their download page.From that page s…
THe viewer will learn how to use NetBeans IDE 8.0 for Windows to perform CRUD operations on a MySql database.
The viewer will learn how to use and create new code templates in NetBeans IDE 8.0 for Windows.

863 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