Solved

How to passing paramter from dw to word

Posted on 2006-07-11
2
642 Views
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.
eg:
 ole_application.selection.insert("example")

 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!)
   ELSE
   //Start open file
    ole_application.Visible = True
    ole_application.Documents.Open(ls_fullpath)
   
   // --- I put my VB coding this here -----

   ole_application.DisconnectObject()
   Destroy ole_application
end if
 
0
Comment
Question by:firza
2 Comments
 
LVL 5

Accepted Solution

by:
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

Mike
0
 
LVL 18

Expert Comment

by:diasroshan
ID: 17097021
Hi,

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...
SELECT  "CUSTOMER"."ID" ,
           "CUSTOMER"."FNAME" ,
           "CUSTOMER"."LNAME" ,
           "CUSTOMER"."ADDRESS" ,
           "CUSTOMER"."CITY" ,
           "CUSTOMER"."STATE" ,
           "CUSTOMER"."ZIP" ,
           "CUSTOMER"."PHONE" ,
           "CUSTOMER"."COMPANY_NAME"    
        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
lole_OLE.documents.Open('C:\customer.doc')

// 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
      Else
            MessageBox('Error','Bookmark not defined.')
            Exit
      End IF      

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

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...
lole_OLE.DisconnectObject()
DESTROY lole_OLE

Hope u get hints from this code...

Cheers,
Rosh
0

Featured Post

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

In our object-oriented world the class is a minimal unit, a brick for constructing our applications. It is an abstraction and we know well how to use it. In well-designed software we are not usually interested in knowing how objects look in memory. …
Jaspersoft Studio is a plugin for Eclipse that lets you create reports from a datasource.  In this article, we'll go over creating a report from a default template and setting up a datasource that connects to your database.
The viewer will learn how to use NetBeans IDE 8.0 for Windows to connect to a MySQL database. Open Services Panel: Create a new connection using New Connection Wizard: Create a test database called eetutorial: Create a new test tabel called ee…
THe viewer will learn how to use NetBeans IDE 8.0 for Windows to perform CRUD operations on a MySql database.

747 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

16 Experts available now in Live!

Get 1:1 Help Now