Okay folks I know this isn't kosher. Nor is it my finest work, but the code
snippet is one I actually have in production and it does work.
Where m_sAccessCmdLine is a member string value and bAccessFound is a
function bollean value defaulted at False:
If File.Exists("c:\Program Files\Microsoft Office\Office12\msaccess.exe") Then
m_sAccessCmdLine = "C:\Program Files\Microsoft
Office\OFFICE12\MSACCESS.EXE " & _
"\\DeptShare\Communications\OutageReport\DevOutage 2002.mdb /x
PrintOutageReports"
m_sAccessCmdLine2 = "C:\Program Files\Microsoft
Office\OFFICE12\MSACCESS.EXE " & _
"\\Fec\EngOps\#DeptShare\Communications\OutageRepo rt\DevOutage2002.mdb
/x UpdateHistTbl"
bAccessFound = True
ElseIf File.Exists("c:\Program Files\Microsoft
Office\Office11\msaccess.exe") Then
m_sAccessCmdLine = "C:\Program Files\Microsoft
Office\OFFICE11\MSACCESS.EXE " & _
"\\DeptShare\Communications\OutageReport\DevOutage 2002.mdb /x
PrintOutageReports"
m_sAccessCmdLine2 = "C:\Program Files\Microsoft
Office\OFFICE11\MSACCESS.EXE " & _
"\\Fec\EngOps\#DeptShare\Communications\OutageRepo rt\DevOutage2002.mdb
/x UpdateHistTbl"
bAccessFound = True
ElseIf File.Exists("c:\Program Files\Microsoft
Office\Office10\msaccess.exe") Then
m_sAccessCmdLine = "C:\Program Files\Microsoft
Office\OFFICE10\MSACCESS.EXE " & _
"\\DeptShare\Communications\OutageReport\DevOutage 2002.mdb /x
PrintOutageReports"
m_sAccessCmdLine2 = "C:\Program Files\Microsoft
Office\OFFICE10\MSACCESS.EXE " & _
"\\Fec\EngOps\#DeptShare\Communications\OutageRepo rt\DevOutage2002.mdb
/x UpdateHistTbl"
bAccessFound = True
ElseIf File.Exists("c:\Program Files\Microsoft Office\Office9\msaccess.exe")
Then
m_sAccessCmdLine = "C:\Program Files\Microsoft
Office\OFFICE9\MSACCESS.EXE " & _
"\\DeptShare\Communications\OutageReport\DevOutage 2002.mdb /x
PrintOutageReports"
m_sAccessCmdLine2 = "C:\Program Files\Microsoft
Office\OFFICE9\MSACCESS.EXE " & _
"\\Fec\EngOps\#DeptShare\Communications\OutageRepo rt\DevOutage2002.mdb /x
UpdateHistTbl"
bAccessFound = True
End If
If bAccessFound Then
Shell(m_sAccessCmdLine, , True)
End If
You can see several problems with the code. Each new version of Access is in
a different location meaning that this code will need maintenance with each
release of Access. I really should not have been so lazy as to resort to a
member variable to carry out this task. A select case statement in place of
the compound If statement would be a little clearer. There are much better
ways to carry this out than using a Shell command. The Process Class comes to
mind.
But, like I said, it does work.
"moondaddy" wrote:
I need to start an ms access 2003 app from a vb.net winforms app and didn't
want to load all the interop stuff for office into the .net project. I
thought that using the shell cmd would be a nice clean way to get it
started. However, when I call the shell cmd, I get a "File Not Found"
error. here's my code:
Dim ClientPath As String = Directory.GetCurrentDirectory & "\" &
System.Configuration.ConfigurationSettings.AppSett ings("ClientName")
If File.Exists(ClientPath) Then
'Code hits this line
Console.WriteLine("exists")
Else
Console.WriteLine("exists not")
End If
Dim ProcID As Integer
ProcID = Shell( ClientPath, AppWinStyle.NormalFocus)
'Also tried the line below
'ProcID = Shell("""" & ClientPath & """", AppWinStyle.NormalFocus)
Any ideas how I can get this running?
Thanks.
--
mo*******@nospam.com