Opening Access from Word

S

Slow Learner

I have a Word document which I wish to have close and open an Access Database
form.

This is the code I have put cmdAccess1 Click which shows under
Project(Viable) Microsoft Word Objects:

Private Sub cmdAccess1_Click()

On Error GoTo Err_cmdAccess1_Click

Dim oApp As Object

Set oApp = CreateObject("Access.Application")
oApp.Visible = True
oApp.Database.Open "c:\test\access\TEST.mdb"


Exit_cmdAccess1_Click:
Exit Sub

Err_cmdAccess1_Click:
MsgBox Err.Description
Resume Exit_cmdAccess1_Click

End Sub

If all went well and the Access database would open and at a Switchboard
form for the user to navigate through and close the Word program.
Best would be to have it reopen the form that it came from in the database
as there is a command button in Access which opens this report. Have no idea
how to do this but the code above is my start.
 
G

Graham Mayor

As my name appears in the subject, I guess you intend an answer from me;
however I know nothing about Access so cannot assist.
Try an Access and/or vba newsgroup.

--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP


<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 
S

Slow Learner

Thanks and yes I thought maybe you could shed some light on how to do this in
the Word program.
 
C

Cindy M -WordMVP-

Hi =?Utf-8?B?U2xvdyBMZWFybmVy?=,
I have a Word document which I wish to have close and open an Access Database
form.
Are you still looking for help with this, or have you found the answer in the
meantime?

Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update Jun 8 2004)
http://www.word.mvps.org

This reply is posted in the Newsgroup; please post any follow question or reply
in the newsgroup and not by e-mail :)
 
S

Slow Learner

Still searching.
I had a response in Word Programming that has me really confused now. I
should think this is a simple procedure but for some reason I do not seem to
be getting my thooughts across.
I am not trying to open or close any other product but Microsoft and I am
using the command button feature in Word.
I do not understand what this function is in Word but in Access it can be
programmed in VB to open anything in that program and-or open Word and then
open a document in Word.
Now once I have the document open I want to be able to place a command
button labeled "Back to Choices" on the word document which takes the viewer
back to the Access database form containing other command buttons opening
other Word and Access choices.
Would appreciate some further insight if you can. Thanks
 
C

Cindy M -WordMVP-

Hi =?Utf-8?B?U2xvdyBMZWFybmVy?=,
I do not understand what this function is in Word but in Access it can be
programmed in VB to open anything in that program and-or open Word and then
open a document in Word.
Now once I have the document open I want to be able to place a command
button labeled "Back to Choices" on the word document which takes the viewer
back to the Access database form containing other command buttons opening
other Word and Access choices.
This last part is the problem, I should think. Word doesn't usually have
buttons on its documents, so there's no slick way to attach code to something
like that. It involves using the VB-Extensibility library for Office to add
code lines to a code module. And, most likely, you'd need to first create the
code module in the document. Furthermore, in doing so, you mark the document as
having macro code in it, which will activate macro security the next time the
user tries to open it.

Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update Jun 8 2004)
http://www.word.mvps.org

This reply is posted in the Newsgroup; please post any follow question or reply
in the newsgroup and not by e-mail :)
 
S

Slow Learner

So in other words not a good idea? Thoughts are that it would be useful in a
workgroup environment using a database application as an intranet. In this
way a person could open the Word document and when finished exit through the
document to intranet neighbourhood again. Or would it be easier to have some
other means of closing out the word document and program?
 
C

Cindy M -WordMVP-

Hi =?Utf-8?B?U2xvdyBMZWFybmVy?=,
So in other words not a good idea? Thoughts are that it would be useful in a
workgroup environment using a database application as an intranet. In this
way a person could open the Word document and when finished exit through the
document to intranet neighbourhood again. Or would it be easier to have some
other means of closing out the word document and program?
Hmmm. For this scenario, I could imagine something along these lines:

1. From the "other application" you click a button that automates Word and opens
the document.

2. At the same time, it also loads an Addin (could be COM or template). This
addin basically adds a toolbar, toolbar button and/or menu command (you choose)
bound to VBA code that will do what you envision.

The differences to what you postulated before:

- You don't need to create code "on the fly"
- The addin can be digitally signed or placed in a trusted location
- The code won't be inside the document (so no worries about it triggering
macro security)

Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update Jun 8 2004)
http://www.word.mvps.org

This reply is posted in the Newsgroup; please post any follow question or reply
in the newsgroup and not by e-mail :)
 
S

Slow Learner

I would like to try this out.
I have the button in the 'other' application (in this case a .mdb file)
which opens MSWord.
Next would be the addin or COM and I would like to see an icon on the
standard toolbar that everyone would have open which when selected takes the
person back.

So now my question, how do you do this? I have not done any addin or COM
things as yet.
Thanks
 
C

Cindy M -WordMVP-

Hi =?Utf-8?B?U2xvdyBMZWFybmVy?=,

Sorry about the late response. I was away for the holidays and am still playing
catchup...
I would like to try this out.
I have the button in the 'other' application (in this case a .mdb file)
which opens MSWord.
Next would be the addin or COM and I would like to see an icon on the
standard toolbar that everyone would have open which when selected takes the
person back.
Easiest would be to create a Word template, saved to a specific location, that
contains the toolbar+macro code to go back.

When your code in Access starts up Word (I'm assuming you're using GetObject,
CreateObject, or the New keyword to do this), then you can load the Addin like
this:

Dim addin as Word.Addin

Set addin = WordApp.Addins.Add "C:\path\filename.dot", False
WordApp.CustomizationContext = Templates(addin.Path & "\" & addin.Name)
WordApp.CommandBars("Name of toolbar").Visible = True

Assuming, when the user should return to the Access database, that the document and
Word application should be closed, first call the Access stuff and bring it to the
front. Then

WordApp.Quit SaveChanges:=WordApp.wdDoNotSaveChanges
1. From the "other application" you click a button that automates Word and opens
the document.

2. At the same time, it also loads an Addin (could be COM or template). This
addin basically adds a toolbar, toolbar button and/or menu command (you choose)
bound to VBA code that will do what you envision.


Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update Jun 8 2004)
http://www.word.mvps.org

This reply is posted in the Newsgroup; please post any follow question or reply in
the newsgroup and not by e-mail :)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top