Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

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

Posted on 2008-06-23
2
Medium Priority
?
332 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 17

Accepted Solution

by:
Natchiket earned 200 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

Use Case: Protecting a Hybrid Cloud Infrastructure

Microsoft Azure is rapidly becoming the norm in dynamic IT environments. This document describes the challenges that organizations face when protecting data in a hybrid cloud IT environment and presents a use case to demonstrate how Acronis Backup protects all data.

Question has a verified solution.

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

Access developers frequently have requirements to interact with Excel (import from or output to) in their applications.  You might be able to accomplish this with the TransferSpreadsheet and OutputTo methods, but in this series of articles I will di…
If you need a simple but flexible process for maintaining an audit trail of who created, edited, or deleted data from a table, or multiple tables, and you can do all of your work from within a form, this simple Audit Log will work for you.
Learn how to make your own table of contents in Microsoft Word using paragraph styles and the automatic table of contents tool. We'll be using the paragraph styles in Word’s Home toolbar to help you create a table of contents. Type out your initial …
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…

688 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