Fellow Monks,

I am having database in MS Access. In a table, I have many columns in which some columns have normal text and some columns have object inserted through OLE (in my case, Word object has been inserted). By the below code, I can able to retrieve the data from the columns which has normal text and i can able to print in new document perfectly. But i cannot able to get the data properly from the column which has word object. When I write the data which I got from the word object in a new word document, I am getting junk characters. Is there any other way to retrive the data from the word object and write into another word document? Have anyone else come across with this type of work?

Also to check, i manually opened the word object link in the database and it has data in it.

Specifications: Perl 5.8.6, Windows 2000, MS Access 2000

use strict; use warnings; use DBI; use Win32::OLE; # check if Word exists and is running my $word = Win32::OLE->GetActiveObject('Word.Application'); die "Word not Installed" if $@; # start Word program instance if required or die if unable to unless (defined $word) { $word = Win32::OLE->new('Word.Application', sub { $_[0]->Quit; } ) + or die 'Cannot start Word'; } # hide/show the document $word->{Visible} = 0; # Create new document my $d = $word->Documents->Add; # define selection my $s = $word->Selection; #set lines to be written to document ######################### retrive data from MS Access ################ +## my $db_file = 'D:\test\Test2000Format.mdb'; my $dbh = DBI->connect( 'dbi:ADO:Provider=Microsoft.Jet.OLEDB.4.0;Data Source='.$db_file, ) or die $DBI::errstr; my $sqlstatement="SELECT Library FROM Manuscripts"; #working perfectly +, Library column has normal text #$sqlstatement="SELECT MSContents FROM Manuscripts"; #MScontents colu +mn has OLE word object my $sth = $dbh->prepare($sqlstatement); $sth->execute || die "Could not execute SQL statement ... maybe inv +alid?"; #output database results while (my @row = $sth->fetchrow_array) { print @row,"\n"; my $text = "@row"; #just for testing $s->TypeText($text); #write in another new doc } # save our object $word->WordBasic->FileSaveAs("D:\\test\\new.doc"); #new word document

Prasad


In reply to Retrieve data from MS Access which has Columns with OLE Object by prasadbabu

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.