Solved

VBA - Controlling Access from Word:  Create .mdb & table without opening Access?

Posted on 2008-06-23
2
323 Views
Last Modified: 2013-11-27
Hi All

Please can you tell me if, using VBA from Word, it is possible to create a new table in an existing Access database without opening Access?  Currently I am using the attached code which, although it works fine, displays a macro security warning when it opens the database.  I know that I can set the macro security in Access to low, or digitally sign the code, but am thinking that, if I can achieve this without actually opening Access, then I won't need to do either.  Also, would Access need to be installed on a user's machine in order for this code to work?  If so, is there a better way to do this so that it doesn't need to be installed?

Any help appreciated as always.


Set objAccess = CreateObject("Access.Application")

With objAccess

    .OpenCurrentDatabase (C:\Test\MyDB.mdb)

    Set dBase = objAccess.CurrentDb

    Set tdf = dbs.CreateTableDef("Contacts")

    Set fld = tdf. _

    CreateField("Surname", DB_Text, 50)

    tdf.Fields.Append fld

    dBase.TableDefs.Append tdf

End with

Open in new window

0
Comment
Question by:MonteDelMar
2 Comments
 
LVL 17

Accepted Solution

by:
Natchiket earned 50 total points
ID: 21845902
you should be able to it as long as DAO is installed on the machine, see
http://accessblog.net/2007/06/how-to-get-reference-to-dbengine.html
You need to be careful of the version, and I'm not sure if DAO is normally installed unless access is, in any case it should be straightforward to copy and register it.

However once you've got a handle on the DBEngine the rest will be plain sailing

Function testDBE()
Dim dbe As Object
Dim dBase As Object

Set dbe = CreateObject("DAO.DBEngine.36")
Set dBase = dbe.OpenDatabase("C:\Test\MyDB.mdb")
'etc as for your code

End Function
0
 

Author Comment

by:MonteDelMar
ID: 21845986
My hero!  Thank you so much for that - works a treat.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Shortcuts in Word Just the other day I had a training for Microsoft and they wanted me to show how well the new Windows and Office behaved on a touch device, which by the way is great, but it was only then that I realized that using keyboard shortc…
Preface: When I started this series, I used the term CommandBars because that is the Office Object class that it discusses. Unfortunately, when Microsoft introduced Office 2007, they replaced the standard Commandbar menus with "The Ribbon" and rem…
Basics of query design. Shows you how to construct a simple query by adding tables, perform joins, defining output columns, perform sorting, and apply criteria.
In Microsoft Access, learn how to “cascade” or have the displayed data of one combo control depend upon what’s entered in another. Base the dependent combo on a query for its row source: Add a reference to the first combo on the form as criteria i…

919 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

15 Experts available now in Live!

Get 1:1 Help Now