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_sAccessCmdLin e 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_sAccessCmdLin e = "C:\Program Files\Microsoft
Office\OFFICE12 \MSACCESS.EXE " & _
"\\DeptShare\Co mmunications\Ou tageReport\DevO utage2002.mdb /x
PrintOutageRepo rts"
m_sAccessCmdLin e2 = "C:\Program Files\Microsoft
Office\OFFICE12 \MSACCESS.EXE " & _
"\\Fec\EngOps\# DeptShare\Commu nications\Outag eReport\DevOuta ge2002.mdb
/x UpdateHistTbl"
bAccessFound = True
ElseIf File.Exists("c: \Program Files\Microsoft
Office\Office11 \msaccess.exe") Then
m_sAccessCmdLin e = "C:\Program Files\Microsoft
Office\OFFICE11 \MSACCESS.EXE " & _
"\\DeptShare\Co mmunications\Ou tageReport\DevO utage2002.mdb /x
PrintOutageRepo rts"
m_sAccessCmdLin e2 = "C:\Program Files\Microsoft
Office\OFFICE11 \MSACCESS.EXE " & _
"\\Fec\EngOps\# DeptShare\Commu nications\Outag eReport\DevOuta ge2002.mdb
/x UpdateHistTbl"
bAccessFound = True
ElseIf File.Exists("c: \Program Files\Microsoft
Office\Office10 \msaccess.exe") Then
m_sAccessCmdLin e = "C:\Program Files\Microsoft
Office\OFFICE10 \MSACCESS.EXE " & _
"\\DeptShare\Co mmunications\Ou tageReport\DevO utage2002.mdb /x
PrintOutageRepo rts"
m_sAccessCmdLin e2 = "C:\Program Files\Microsoft
Office\OFFICE10 \MSACCESS.EXE " & _
"\\Fec\EngOps\# DeptShare\Commu nications\Outag eReport\DevOuta ge2002.mdb
/x UpdateHistTbl"
bAccessFound = True
ElseIf File.Exists("c: \Program Files\Microsoft Office\Office9\ msaccess.exe")
Then
m_sAccessCmdLin e = "C:\Program Files\Microsoft
Office\OFFICE9\ MSACCESS.EXE " & _
"\\DeptShare\Co mmunications\Ou tageReport\DevO utage2002.mdb /x
PrintOutageRepo rts"
m_sAccessCmdLin e2 = "C:\Program Files\Microsoft
Office\OFFICE9\ MSACCESS.EXE " & _
"\\Fec\EngOps\# DeptShare\Commu nications\Outag eReport\DevOuta ge2002.mdb /x
UpdateHistTbl"
bAccessFound = True
End If
If bAccessFound Then
Shell(m_sAccess CmdLine, , 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.GetCu rrentDirectory & "\" &
System.Configur ation.Configura tionSettings.Ap pSettings("Clie ntName")
If File.Exists(Cli entPath) Then
'Code hits this line
Console.WriteLi ne("exists")
Else
Console.WriteLi ne("exists not")
End If
Dim ProcID As Integer
ProcID = Shell( ClientPath, AppWinStyle.Nor malFocus)
'Also tried the line below
'ProcID = Shell("""" & ClientPath & """", AppWinStyle.Nor malFocus)
Any ideas how I can get this running?
Thanks.
--
mo*******@nospa m.com