Link to home
Start Free TrialLog in
Avatar of Mark01
Mark01Flag for United States of America

asked on

Access 2010 Process.Start Error

I receive an "Object variable or With block variable not set" error when I try to run the following code in Access 2010:
 Dim objProcess As Object
 objProcess.Start ("C:\WINDOWS\system32\calc.exe")

However, the following code runs in VB.Net:
Dim StartCalc As Process = System.Diagnostics.Process.Start("C:\WINDOWS\system32\calc.exe")

Please help resolve the error.
Avatar of John Tsioumpris
John Tsioumpris
Flag of Greece image

If you after to open calculator from Access then this code does the job :
Private Sub ActivateCalculator()
Dim RetVal As Variant
  RetVal = Shell("calc.exe", 1)
End Sub

Open in new window

Avatar of Daniel Pineault
Daniel Pineault

I agree with John, Shell would be the approach I'd use to launch another application.

If you are trying to stick with you approach, how have you set your object variable exactly?
 Dim objProcess As Object
 Set objProcess = ???
 objProcess.Start ("C:\WINDOWS\system32\calc.exe")

Open in new window

You can use an API call:

Option Compare Database
Option Explicit

Private Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hWnd As Long, ByVal lpOperation As String, ByVal lpFile As String, ByVal lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long

Public Function OpenCalc()

    ShellExecute 0, "open", "calc.exe", vbNullString, vbNullString, vbNormalFocus

End Function

Open in new window

But Shell seems much faster to open Calculator.
Avatar of Mark01

ASKER

Thank you for the code, John and Gustav.  @Daniel Pineault: I don’t know how to set the object variable, which is why I asked the question. I searched the web and found several examples of how to use the  Process object with VBA, but there were no process.start examples.
ASKER CERTIFIED SOLUTION
Avatar of John Tsioumpris
John Tsioumpris
Flag of Greece image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Mark01

ASKER

Thank you Daniel, Gustav and John. I will work with the code that you provided.
You are welcome!