# Opening an MS Access file and a macro

**URL:** <https://forum.inductiveautomation.com/t/opening-an-ms-access-file-and-a-macro/87601>\
**Category:** Ignition\
**Created:** [March 19, 2024, 11:58pm UTC](https://forum.inductiveautomation.com/t/opening-an-ms-access-file-and-a-macro/87601 "2024-03-19T23:58:17Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![Faz](https://avatars.discourse-cdn.com/v4/letter/f/85e7bf/32.png) [@Faz](https://forum.inductiveautomation.com/u/Faz)\
**Post date:** [March 19, 2024, 11:58pm UTC](https://forum.inductiveautomation.com/t/opening-an-ms-access-file-and-a-macro/87601/1 "2024-03-19T23:58:17Z")

</div>

Hi all, I'm trying to open an MS Access macro in Ignition. I've used the script console but no luck getting it to open even the file.

```auto
system.util.execute(['C:\\Users\\Ignition\\Ignition.mdb'])

```

This is the error:

```auto
Java Traceback:
Traceback (most recent call last):
  File "<input>", line 1, in <module>
	at java.base/java.lang.ProcessBuilder.start(Unknown Source)

	at java.base/java.lang.ProcessBuilder.start(Unknown Source)

	at java.base/java.lang.Runtime.exec(Unknown Source)

	at java.base/java.lang.Runtime.exec(Unknown Source)

	at com.inductiveautomation.ignition.common.script.builtin.SystemUtilities.execute(SystemUtilities.java:146)

	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)

	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)

	at java.base/java.lang.reflect.Method.invoke(Unknown Source)

java.io.IOException: java.io.IOException: Cannot run program "C:\Users\Ignition\Ignition.accdb": CreateProcess error=2, The system cannot find the file specified

	at org.python.core.Py.JavaError(Py.java:547)

	at org.python.core.Py.JavaError(Py.java:538)

	at org.python.core.PyReflectedFunction. __call__ (PyReflectedFunction.java:192)

	at com.inductiveautomation.ignition.common.script.ScriptManager$ReflectedInstanceFunction. __call__ (ScriptManager.java:553)

	at org.python.core.PyObject. __call__ (PyObject.java:461)

	at org.python.core.PyObject. __call__ (PyObject.java:465)

	at org.python.pycode._pyx49.f$0(<input>:1)

	at org.python.pycode._pyx49.call_function(<input>)

	at org.python.core.PyTableCode.call(PyTableCode.java:173)

	at org.python.core.PyCode.call(PyCode.java:18)

	at org.python.core.Py.runCode(Py.java:1687)

	at org.python.core.Py.exec(Py.java:1731)

	at org.python.util.PythonInterpreter.exec(PythonInterpreter.java:277)

	at org.python.util.InteractiveInterpreter.runcode(InteractiveInterpreter.java:130)

	at com.inductiveautomation.ignition.designer.gui.tools.jythonconsole.JythonConsole$ConsoleWorker.doInBackground(JythonConsole.java:628)

	at com.inductiveautomation.ignition.designer.gui.tools.jythonconsole.JythonConsole$ConsoleWorker.doInBackground(JythonConsole.java:616)

	at java.desktop/javax.swing.SwingWorker$1.call(Unknown Source)

	at java.base/java.util.concurrent.FutureTask.run(Unknown Source)

	at java.desktop/javax.swing.SwingWorker.run(Unknown Source)

	at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)

	at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)

	at java.base/java.lang.Thread.run(Unknown Source)

Caused by: java.io.IOException: Cannot run program "C:\Users\Ignition\Ignition.accdb": CreateProcess error=2, The system cannot find the file specified

	at java.base/java.lang.ProcessBuilder.start(Unknown Source)

	at java.base/java.lang.ProcessBuilder.start(Unknown Source)

	at java.base/java.lang.Runtime.exec(Unknown Source)

	at java.base/java.lang.Runtime.exec(Unknown Source)

	at com.inductiveautomation.ignition.common.script.builtin.SystemUtilities.execute(SystemUtilities.java:146)

	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)

	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)

	at java.base/java.lang.reflect.Method.invoke(Unknown Source)

	at org.python.core.PyReflectedFunction. __call__ (PyReflectedFunction.java:190)

	... 19 more

Caused by: java.io.IOException: CreateProcess error=2, The system cannot find the file specified

	at java.base/java.lang.ProcessImpl.create(Native Method)

	at java.base/java.lang.ProcessImpl.<init>(Unknown Source)

	at java.base/java.lang.ProcessImpl.start(Unknown Source)

	... 29 more

Traceback (most recent call last):
  File "<input>", line 1, in <module>
	at java.base/java.lang.ProcessBuilder.start(Unknown Source)

	at java.base/java.lang.ProcessBuilder.start(Unknown Source)

	at java.base/java.lang.Runtime.exec(Unknown Source)

	at java.base/java.lang.Runtime.exec(Unknown Source)

	at com.inductiveautomation.ignition.common.script.builtin.SystemUtilities.execute(SystemUtilities.java:146)

	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)

	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)

	at java.base/java.lang.reflect.Method.invoke(Unknown Source)

java.io.IOException: java.io.IOException: Cannot run program "C:\Users\Ignition\Ignition.accdb": CreateProcess error=2, The system cannot find the file specified
>>> 
Java Traceback:
Traceback (most recent call last):
  File "<input>", line 1, in <module>
	at java.base/java.lang.ProcessBuilder.start(Unknown Source)

	at java.base/java.lang.ProcessBuilder.start(Unknown Source)

	at java.base/java.lang.Runtime.exec(Unknown Source)

	at java.base/java.lang.Runtime.exec(Unknown Source)

	at com.inductiveautomation.ignition.common.script.builtin.SystemUtilities.execute(SystemUtilities.java:146)

	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)

	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)

	at java.base/java.lang.reflect.Method.invoke(Unknown Source)

java.io.IOException: java.io.IOException: Cannot run program "C:\Users\Ignition\Ignition.mdb": CreateProcess error=32, The process cannot access the file because it is being used by another process

	at org.python.core.Py.JavaError(Py.java:547)

	at org.python.core.Py.JavaError(Py.java:538)

	at org.python.core.PyReflectedFunction. __call__ (PyReflectedFunction.java:192)

	at com.inductiveautomation.ignition.common.script.ScriptManager$ReflectedInstanceFunction. __call__ (ScriptManager.java:553)

	at org.python.core.PyObject. __call__ (PyObject.java:461)

	at org.python.core.PyObject. __call__ (PyObject.java:465)

	at org.python.pycode._pyx51.f$0(<input>:1)

	at org.python.pycode._pyx51.call_function(<input>)

	at org.python.core.PyTableCode.call(PyTableCode.java:173)

	at org.python.core.PyCode.call(PyCode.java:18)

	at org.python.core.Py.runCode(Py.java:1687)

	at org.python.core.Py.exec(Py.java:1731)

	at org.python.util.PythonInterpreter.exec(PythonInterpreter.java:277)

	at org.python.util.InteractiveInterpreter.runcode(InteractiveInterpreter.java:130)

	at com.inductiveautomation.ignition.designer.gui.tools.jythonconsole.JythonConsole$ConsoleWorker.doInBackground(JythonConsole.java:628)

	at com.inductiveautomation.ignition.designer.gui.tools.jythonconsole.JythonConsole$ConsoleWorker.doInBackground(JythonConsole.java:616)

	at java.desktop/javax.swing.SwingWorker$1.call(Unknown Source)

	at java.base/java.util.concurrent.FutureTask.run(Unknown Source)

	at java.desktop/javax.swing.SwingWorker.run(Unknown Source)

	at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)

	at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)

	at java.base/java.lang.Thread.run(Unknown Source)

Caused by: java.io.IOException: Cannot run program "C:\Users\Ignition\Ignition.mdb": CreateProcess error=32, The process cannot access the file because it is being used by another process

	at java.base/java.lang.ProcessBuilder.start(Unknown Source)

	at java.base/java.lang.ProcessBuilder.start(Unknown Source)

	at java.base/java.lang.Runtime.exec(Unknown Source)

	at java.base/java.lang.Runtime.exec(Unknown Source)

	at com.inductiveautomation.ignition.common.script.builtin.SystemUtilities.execute(SystemUtilities.java:146)

	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)

	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)

	at java.base/java.lang.reflect.Method.invoke(Unknown Source)

	at org.python.core.PyReflectedFunction. __call__ (PyReflectedFunction.java:190)

	... 19 more

Caused by: java.io.IOException: CreateProcess error=32, The process cannot access the file because it is being used by another process

	at java.base/java.lang.ProcessImpl.create(Native Method)

	at java.base/java.lang.ProcessImpl.<init>(Unknown Source)

	at java.base/java.lang.ProcessImpl.start(Unknown Source)

	... 29 more

Traceback (most recent call last):
  File "<input>", line 1, in <module>
	at java.base/java.lang.ProcessBuilder.start(Unknown Source)

	at java.base/java.lang.ProcessBuilder.start(Unknown Source)

	at java.base/java.lang.Runtime.exec(Unknown Source)

	at java.base/java.lang.Runtime.exec(Unknown Source)

	at com.inductiveautomation.ignition.common.script.builtin.SystemUtilities.execute(SystemUtilities.java:146)

	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)

	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)

	at java.base/java.lang.reflect.Method.invoke(Unknown Source)

java.io.IOException: java.io.IOException: Cannot run program "C:\Users\Ignition\Ignition.mdb": CreateProcess error=32, The process cannot access the file because it is being used by another process

```

Any advice?

---

<div class="post-metadata">

**Author:** ![josborn](https://avatars.discourse-cdn.com/v4/letter/j/4bbf92/32.png) [@josborn](https://forum.inductiveautomation.com/u/josborn)\
**Post date:** [March 20, 2024, 12:13am UTC](https://forum.inductiveautomation.com/t/opening-an-ms-access-file-and-a-macro/87601/2 "2024-03-20T00:13:59Z")

</div>

Something like this, though it will depend on what version of office you have installed:

```auto
system.util.execute(['C:\\Program Files\\Microsoft Office\\root\\Office16\MSACCESS.EXE', 'C:\\Users\\Ignition\\Ignition.mdb'])

```

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [March 20, 2024, 12:16am UTC](https://forum.inductiveautomation.com/t/opening-an-ms-access-file-and-a-macro/87601/3 "2024-03-20T00:16:27Z")

</div>

> [@josborn](#):
>
> will depend on

And also only work in a Vision client. Perspective clients cannot run anything local to the user.

---

<div class="post-metadata">

**Author:** ![paul-griffith](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul-griffith/32/37249_2.png) [@paul-griffith](https://forum.inductiveautomation.com/u/paul-griffith)\
**Post date:** [March 20, 2024, 12:19am UTC](https://forum.inductiveautomation.com/t/opening-an-ms-access-file-and-a-macro/87601/4 "2024-03-20T00:19:11Z")

</div>

I would probably use `start`, to lean on the OS and not require an explicit path to an executable:  
`system.util.execute(["start", "", "C:\\Users\\Ignition\\Ignition.mdb"])`

[https://ss64.com/nt/start.html](https://ss64.com/nt/start.html)

The empty string is the value you **must** supply for the 'title' of the launched process, apparently.

---

<div class="post-metadata">

**Author:** ![Faz](https://avatars.discourse-cdn.com/v4/letter/f/85e7bf/32.png) [@Faz](https://forum.inductiveautomation.com/u/Faz)\
**Post date:** [March 20, 2024, 4:17pm UTC](https://forum.inductiveautomation.com/t/opening-an-ms-access-file-and-a-macro/87601/5 "2024-03-20T16:17:53Z")

</div>

This doesn't seems to work for me.  
Anyway, above code @josborn showed worked.  
Thank you all.

---

<div class="post-metadata">

**Author:** ![Felipe\_CRM](https://avatars.discourse-cdn.com/v4/letter/f/dfb087/32.png) [@Felipe\_CRM](https://forum.inductiveautomation.com/u/Felipe_CRM)\
**Post date:** [March 20, 2024, 6:11pm UTC](https://forum.inductiveautomation.com/t/opening-an-ms-access-file-and-a-macro/87601/6 "2024-03-20T18:11:29Z")

</div>

It didn't like `start` by itself, only way I got it to run was

```auto
system.util.execute(["cmd.exe", "/c", "start \"\" \"Path\\To\\File\""])

```

or alternatively

```auto
system.util.execute(["cmd", "/c", "start", '""', "Path\\To\\File"])

```

Also worked using `subprocess.call()` with `shell=True`, for probably the same reasons.

---

<div class="post-metadata">

**Author:** ![Faz](https://avatars.discourse-cdn.com/v4/letter/f/85e7bf/32.png) [@Faz](https://forum.inductiveautomation.com/u/Faz)\
**Post date:** [March 20, 2024, 8:30pm UTC](https://forum.inductiveautomation.com/t/opening-an-ms-access-file-and-a-macro/87601/7 "2024-03-20T20:30:56Z")

</div>

One more question: How do I close the file that i open? Is there a command when i import os?  
I tried using

```auto
import os
os.remove('C:\\Users\\Ignition\\Ignition.mdb')

```

But it completely deleted my file.

---

<div class="post-metadata">

**Author:** ![josborn](https://avatars.discourse-cdn.com/v4/letter/j/4bbf92/32.png) [@josborn](https://forum.inductiveautomation.com/u/josborn)\
**Post date:** [March 20, 2024, 8:43pm UTC](https://forum.inductiveautomation.com/t/opening-an-ms-access-file-and-a-macro/87601/8 "2024-03-20T20:43:18Z")

</div>

I haven't used this but i think os.close() would do it.

> **[Python os.close() Method](https://www.w3schools.com/python/ref_os_close.asp)**
>
> W3Schools offers free online tutorials, references and exercises in all the major languages of the web. Covering popular subjects like HTML, CSS, JavaScript, Python, SQL, Java, and many, many more.

---

<div class="post-metadata">

**Author:** ![paul-griffith](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul-griffith/32/37249_2.png) [@paul-griffith](https://forum.inductiveautomation.com/u/paul-griffith)\
**Post date:** [March 20, 2024, 8:50pm UTC](https://forum.inductiveautomation.com/t/opening-an-ms-access-file-and-a-macro/87601/9 "2024-03-20T20:50:19Z")

</div>

What do you mean by 'close'?

`system.util.execute` is launching a process. That's it. What that process does with any arguments passed into it is up to that process.  
`system.util.execute` also does not return a process ID or handle or anything. If _you_ want to kill the launched process, you'll have to discover it yourself, _or_ use a different mechanism to launch it (i.e. search on this forum for usage examples of Java's `ProcessBuilder`).

---

<div class="post-metadata">

**Author:** ![Faz](https://avatars.discourse-cdn.com/v4/letter/f/85e7bf/32.png) [@Faz](https://forum.inductiveautomation.com/u/Faz)\
**Post date:** [March 20, 2024, 8:54pm UTC](https://forum.inductiveautomation.com/t/opening-an-ms-access-file-and-a-macro/87601/10 "2024-03-20T20:54:18Z")

</div>

So pretty much I'm calling a DLL API in Access. I've written some VBA code to handle the API in Access side. When i open the Access file, it runs the VBA and after that i want to close the Access file. If i keep it open, every time i call the Access file from Ignition, it'll just open another instance.  
I guess I'll try looking in Java's ProcessBuilder.

---

<div class="post-metadata">

**Author:** ![josborn](https://avatars.discourse-cdn.com/v4/letter/j/4bbf92/32.png) [@josborn](https://forum.inductiveautomation.com/u/josborn)\
**Post date:** [March 20, 2024, 8:55pm UTC](https://forum.inductiveautomation.com/t/opening-an-ms-access-file-and-a-macro/87601/11 "2024-03-20T20:55:41Z")

</div>

Could you just close it on the access side with [DoCmd.Quit method (Access) | Microsoft Learn](https://learn.microsoft.com/en-us/office/vba/api/access.docmd.quit)

---

<div class="post-metadata">

**Author:** ![Faz](https://avatars.discourse-cdn.com/v4/letter/f/85e7bf/32.png) [@Faz](https://forum.inductiveautomation.com/u/Faz)\
**Post date:** [March 20, 2024, 9:02pm UTC](https://forum.inductiveautomation.com/t/opening-an-ms-access-file-and-a-macro/87601/12 "2024-03-20T21:02:21Z")

</div>

Perfect. This works like a charm. I've added into VBA QuitAccess command.  
Thank you all.
