Solved

Programmatically embed Microsoft Word document into Access Database using VB6

Posted on 2004-09-17
15
7,619 Views
Last Modified: 2013-12-25
I am creating a VB6 appliation that logs live data and inserts it into a Access table.  This database also has a main table that contains pertinanent information to the test being run.  This main table has to contain an embedded word object inserted at runtime of the VB6 application.
Any suggestions?

Thanks in advance

Tom
0
Comment
Question by:thomasmurray
  • 6
  • 5
  • 3
15 Comments
 
LVL 29

Expert Comment

by:leonstryker
ID: 12085197
I do not suggest doing this.  A better solution would be to write the location of the word document in the databse instead.  If, however you insist on doing it this way then take a look at the ADO Stream object.

http://www.w3schools.com/ado/ado_ref_stream.asp

Leon
0
 

Author Comment

by:thomasmurray
ID: 12086144
The reason that I cannot simply write the location in the database is because the database will be copied and shared by numerous people.  There is no network available to facilitate a link to the document.  

Do you know of a way to embed a document through a VB application using an OLE object?

tom  
0
 
LVL 29

Expert Comment

by:leonstryker
ID: 12086476
>>The reason that I cannot simply write the location in the database is because the database will be copied and shared by numerous people.  

All you would need to do is packadge and deploy the word files along with the database.

>>Do you know of a way to embed a document through a VB application using an OLE object?

What do you mean by embed?  If you mean display the word document in a VB form, then use an OLE container object.  If you mean how to store and retrieve it to the database then use ADO.Stream as I stated above.

Leon
0
 

Author Comment

by:thomasmurray
ID: 12086879
By embed I mean:
  When I run the VB application I want it to insert the document into a cell of the database.  I then want to be able to open up this database on another computer through access and when the user double clicks on the cell, it will bring up the document.
I thought about including this document in the same folder as the database and then just linking it, but I will not be the only person copying the database. I want other people that don't know about the location of the document to be able to simply click on the corresponding cell and the document will open.

thanks

tom

PS.  Thank-you for all of your quick responses
0
 
LVL 29

Expert Comment

by:leonstryker
ID: 12086988
0
 

Author Comment

by:thomasmurray
ID: 12087244
I checked out that site.  That code will allow me to store the document as a biinary file within the database, but then I will have to write another application that can read back in the stream and show it as a document.  I can't do this, because I want the database to be looked at with no additional resources.

What I want to do is the same as if I was inside the access database and had a cell with OLE object as its data type.  If I right click this cell (from within the table view) I have an option to insert object.  
I tried using the stream before, but instead of a word object embedded in the cell, I have 'Long Binary Data' with which access does not know what to do with.

Hope this clears up the question a little

Thanks

tom
0
 
LVL 7

Expert Comment

by:LandyJ
ID: 12087327
Tom,

I replied to your other question under "Databases"  You should only post your questions in one topic area.  And if you must cross-post, please make sure that you state that in BOTH questions.

A couple of questions -- do you need to retain some type of formatting in these Word documents?  Do your users get to modify the documents before they are saved?  Saving OLE Objects, expecially any MS Office document, in a database will cause the db to get very large very fast. Using the Word object model and saving only the text portions of the document, then creating the Word intrepretations on the fly might get you what you want.  It's more complex, but you won't approach Access' 2GB limit quite as fast. (Does it still have that limit?  I know Access2000 did.)

Hope this helps,
Landy
0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 7

Expert Comment

by:LandyJ
ID: 12087361
BTW -- by "only post your questions in one topic area" I meant don't post the same question in multiple topic areas.  Of course you can post different questions in different topic areas.  

Welcome to EE,
Landy

0
 
LVL 7

Expert Comment

by:LandyJ
ID: 12088531
continuing from: http://www.experts-exchange.com/Databases/Q_21135062.html

OK, you want to load the Word document into the Access database using VB, but retreive it by opening Access and going to the table directly?  Where are the documents coming from?  Are you creating them on the fly or do they already exist on the disk and you are just loading them into this db?

If these already exist on the disk somewhere, and you are giving the user the ability to open the tables to retreive the docs, give them the ability to add the docs directly to the table.  
 
If you are creating these on the fly, try setting the Field object (data type OLE Object) equal to the Word object.  I dont' have VB6 installed on this pc and haven't coded in it for a while so I can't test this, but the code should be something like this:

dim objWordDoc As Word.Document
set objWordDoc = new Word.Document

... create doc ....


adoRec.AddNEw
...
Set adoField = objWordDoc
...
adoRec.Update

Try this and see if you can work it out.  If I have time tonight between Friday night festivities (highly doubtful, it's been a crappy week), I'll take a stab at it at home in VB6.  Good luck.

Hope this helps,
Landy


0
 

Author Comment

by:thomasmurray
ID: 12101869
Landy~
Thanks for getting back to me.  To answer your question, the document already exists.  The application that I am creating has a open dialog box that asks the user for the location of the database.  I then want to take this path and embed the document into the database.  This database already exists, and the application will have it open already because there is other data that will already been added programmatically.

So basically what I want to do through my application is the same as if I was inside of Access -> then right-clicked in the table cell that is set to be an OLE object -> then choose insert object -> from file -> then select the document.

Thanks again for your help
Tom
0
 
LVL 7

Expert Comment

by:LandyJ
ID: 12103106
OK, here goes:

Use the Access object model from your VB program and create a Database Object, Table Object, Recordset Object
Navigate to your Table, create a new recordset object for your new record, and then use the InsertObject command/function.  I think you can get there from the recordset, but again, I don't have VB6 on this pc here at the office.  If not, you'll probably have to create a Macro object and go at it from there.

I realize this sounds like a kluge, but at the moment, this all I can think of.  Hope if at least sets you down the right path for a better solution.

Hope this helps,
Landy

0
 
LVL 7

Expert Comment

by:LandyJ
ID: 12291263
Tom,  still need help on this or did you find a good way to do this?  If you found a better way, please make sure you post your solution so that someone else might be helped also (don't forget to request a refund of your points if you found your own solution).
0
 

Author Comment

by:thomasmurray
ID: 12474251
No....  I still haven't found a viable solution.  
Everything that I try doesn't seem to work out very well.  
0
 
LVL 7

Accepted Solution

by:
LandyJ earned 500 total points
ID: 12814557
Refund is ok by me.  
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

706 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

18 Experts available now in Live!

Get 1:1 Help Now