473,414 Members | 1,954 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,414 software developers and data experts.

Running an Access DB macro from within Windows Application

Hi Everyone

Visual Studio 2005
VB 2005
Windows Application

I have a form with one combo box and a button

I want the user to make a selection from the combo box, click the button and have the application run an Access 2003 Macro, the database is embedded in my project.
I receive the following message when the button is clicked:


Microsoft Office Access can't open the database because it is missing, or opened exclusively by another user

The problem must be with the filepath in my code here is the code under the button click event:
Expand|Select|Wrap|Line Numbers
  1. Select Case ComboBox1.SelectedItem
  2.  
  3.             Case "Clear Form"
  4.  
  5.                 Dim oAccess As Access.ApplicationClass
  6.  
  7.                 'Start Access and open the database.
  8.                 oAccess = CreateObject("Access.Application")
  9.                 oAccess.Visible = False
  10.                 oAccess.OpenCurrentDatabase("|DataDirectory|LTDatabase.mdb", False)
  11.                 'Run the macro
  12.                 'oAccess.Run("test2")
  13.  
  14.                 'Clean-up: Quit Access without saving changes to the database.
  15.                 oAccess.DoCmd().Quit(Access.AcQuitOption.acQuitSaveNone)
  16.                 System.Runtime.InteropServices.Marshal.ReleaseComObject(oAccess)
  17.                 oAccess = Nothing
  18.  
  19.         End Select
  20.  
  21.         GC.Collect()
  22.  
If I change the path text to a copy of the Db on my C: drive "c:\LTDatabase.mdb" it works perfectly, so what is wrong with my path? ("|DataDirectory|LTDatabase.mdb", False)
I'm sure it is something very basic that I'm missing....any thoughts would be appreciated.

Lone

UPDATE
It's just dawned on me that Access has no chance of finding "|DataDirectory|LTDatabase.mdb so how am I going to have this functionality in a deployed application mmmmmm scratching head
Nov 20 '08 #1
2 1539
nukefusion
221 Expert 100+
I would say the problem is with the path string "|DataDirectory|LTDatabase.mdb".

You can use a database in a deployed application no problem. If the database is local to the application, upon deployment you can copy it to the ApplicationData folder and work from it there.

You can the open the database using code similar to the following:

Expand|Select|Wrap|Line Numbers
  1. Dim oAccess As Access.ApplicationClass
  2.  
  3.         'Start Access and open the database. 
  4.         oAccess = CreateObject("Access.Application")
  5.         oAccess.Visible = False
  6.  
  7.         Dim dbPath As String
  8.         ' You can use Environment.SpecialFolder.ApplicationData or Environment.SpecialFolder.CommonApplicationData
  9.         ' depending on whether the DB needs to be accessed by just the current user or all users of the computer
  10.         dbPath = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\LTDatabase.mdb"
  11.         oAccess.OpenCurrentDatabase(dbPath, False)
Nov 20 '08 #2
Thanks very much for your reply nuke,

Have added the code but am still receiving the same error....As this is my first windows app deployment I'm going to go away and investigate the use of the ApplicationData folder and how it fits into the scheme of things, just very unclear to me at the moment.
Nov 20 '08 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

11
by: Mike MacSween | last post by:
My client has an MS Access database application on her local machine. I have full access to that in terms of changing the design. I've got a simple PHP/MySql application on shared hosting, so no...
63
by: Jerome | last post by:
Hi, I'm a bit confused ... when would I rather write an database application using MS Access and Visual Basic and when (and why) would I rather write it using Visual Studio .Net? Is it as easy...
10
by: ThunderMusic | last post by:
Hi, How can I get if the Windows running is a server version? Is there a property somewhere that can tell me if the Windows version is a server edition (including server, advanced server, web...
2
by: E Harris | last post by:
Hello all. I want to schedule an Access macro to run. The macro runs 3 make-table queries. The best way I thought to accomplish this is to create a shortcut, and then use the task scheduler...
52
by: Neil | last post by:
We are running an Access 2000 MDB with a SQL 7 back end. Our network guy is upgrading to Windows Server 2003 and wants to upgrade Office and SQL Server at the same time. We're moving to SQL Server...
23
by: Reggie | last post by:
Hi and TIA. I developed several A2K dbs which are now being run on my clients computer which have been upgraded to Access 03. I'm not sure exactly what they mean but of you know or could point me...
2
by: mscurto | last post by:
Is there a way to set up access to open and run a query in a particular database at a particular time each day? This would be run from a Windows 2000 desktop.
1
by: Sue | last post by:
Hi (Also posted in getting started group) Is it possible to have a Macro that runs (importing tables) at a specific time each day without user input. Also wondered if its possible to use access...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.