PC Review


Reply
Thread Tools Rate Thread

Close one mdb open another

 
 
Arturo
Guest
Posts: n/a
 
      28th Jul 2008
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.
 
Reply With Quote
 
 
 
 
Graham Mandeno
Guest
Posts: n/a
 
      29th Jul 2008
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.



 
Reply With Quote
 
Arturo
Guest
Posts: n/a
 
      29th Jul 2008
That worked great. I called the script from within Access.

Thank you.

"Graham Mandeno" wrote:

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

>
>
>

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Open a new DB and close the close the original DB PJFry Microsoft Access Form Coding 2 26th Feb 2009 12:05 AM
How do I make Word stay open when I close my one open document? lauren38 Microsoft Word Document Management 2 10th Dec 2008 03:36 PM
Dialog Box is open Click Ok then close open diallog boxes word 2 gadget268 Microsoft Word Document Management 4 24th Oct 2008 12:45 PM
Excel-Can't close 1 open Workbook without closing other open Workb =?Utf-8?B?ZnJhbWluZ2hhbQ==?= Microsoft Excel Misc 1 18th Oct 2004 08:59 PM
OL2003: I want all mails open to stay open even if I close OL =?Utf-8?B?Q3JhYmJ5IE9mZmljZSBMYWR5IChNUyk=?= Microsoft Outlook Discussion 3 25th Aug 2004 12:28 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 06:33 PM.