Open a Microsoft Access file from within Word

M

Mark64

I don't know if this is even possible or if this is just a stupid question.
But does anyone know if it is possible to create a macro that I can add to
the toolbar that I can just press to open an existing Microsoft Access file.

Thank you
 
M

Mark64

Is there a function within Word or do I need to input an open statement using
Visual Basic. I am new to Visual Basic and I haven't really learned the
language.
 
J

Jezebel

Are you opening the Access file as an Access application, or simply opening
the database? (The methods you use are completely different.) Either way,
there's a more to it than you can expect to get answered in a posting. Trawl
the VB/VBA websites: there are any number of examples.
 
M

Mark64

I would like for it to open Access with the database as its own window and
switch to it as well. Basically after I am finished writing a report I have
to go fill the log in the database. Which means I have to go to the folder
where it is located and then open it up, which usually takes awhile. So I
would like just a button on Word that I can press to fill out the information
that way I don't forget to fill in the database. Lets assume the access file
name is: test.mdb
 
J

Jezebel

Read help on GetObject() and CreateObject().

As an alternative, you could create a UserForm in Word to collect the
information; then use an SQL statement to insert the data directly into the
database.

Or simpler still, just add a destop shortcut to the database.
 
M

Mark64

Jezebel,

Okay, I used the GetObject function like the help says and I don't get any
errors, but the access file does not open (I also tried it with an Excel file
and that wouldn't open either). I am not for sure if I was clear on this but
when I wanted to open Access I just wanted a button in Word basically to
remind me to fill in the information in Access and it would be a quick key to
get there, the information in the Access database has nothing to do with the
Word document, I am not inputting data from the Word document into the Access
document. Sorry if I have been sort of vague, I am trying to understand the
VBA. Anyways here is what I put in Visual Basic:

Sub Macro1()

Dim Object1 As Object
Set Object1 = GetObject("C:\Documents and Settings\My Documents\test.mdb")

End Sub

Do you have any suggestions? Thank you for all your help!
 
J

Jezebel

I suggest you actually READ the help file and look at the examples.
GetObject returns a reference to the object -- Excel file, Access db,
whatever. It doesn't DO anything with the object -- YOU have to call the
object's methods to make something happen (ie make it visible, activate it,
etc).
 

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