Opening an MS Access file and a macro

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.

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

This is the error:

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?

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

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

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

3 Likes

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

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

1 Like

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

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

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

or alternatively

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

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

2 Likes

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

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

But it completely deleted my file.

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

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).

1 Like

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.

Could you just close it on the access side with DoCmd.Quit method (Access) | Microsoft Learn

4 Likes

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

1 Like