Hi Arturo
Yes, the spaces are what is causing the problem. If your file or folder
names have spaces then the whole filename needs to be enclosed in quotes.
Two consecutive quotes inside a literal string in VBA or VBScript are
interpreted as one quote, so your Shell command should be:
"MSAccess.exe ""C:\Folder 1\File 1.mdb"""
Is this VBA code running from inside the database you are closing? If so
then using WMIService and WScript is way over the top. All you should need
is:
Shell "MSAccess.exe ""C:\Folder 1\File 1.mdb""", vbMaximizedFocus
Application.Quit
--
Good Luck :-)
Graham Mandeno [Access MVP]
Auckland, New Zealand
"Arturo" <(E-Mail Removed)> wrote in message
news:BA5A504C-0425-4DED-B6B0-(E-Mail Removed)...
>I used to use a script to close one Access DB and then
> open another. The script is as follows:
>
> strComputer = "."
> Set objWMIService = GetObject("winmgmts:" _
> & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
> Set colProcessList = objWMIService.ExecQuery _
> ("Select * from Win32_Process Where Name = 'MSAccess.exe'")
> For Each objProcess in colProcessList
> objProcess.Terminate()
> Next
> Set objShell = CreateObject("WScript.Shell")
> objShell.Run "MSAccess.exe C:\Folder 1\File 1.mdb"
>
> I do have spaces in the names but it never mattered before.
> I run it and keep getting the message that an incorrect command
> was used to open access. Anybody know what is wrong or do you
> have another script?
>
> Thank you.
|