Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Automatically delete an .mdb after it exits

Status
Not open for further replies.

eschloss

Technical User
Mar 30, 2009
2
I have a script which copies an .mdb file and runs the copy. When the .mdb copy is closed, it then deletes it. However, I would rather use the run method, I believe, rather than a looping method. This is where I need help, I do not know how to correctly implement it. Also, I don't know the path of msaccess.exe on the network at work. Do I need to know it?

I also want to maintain the parameters called when opening the copy .mdb currently, specifically automationsecurity.

I have read the following, but my brain has not clicked yet(started learning VBS this weekend).


Thanks in advance,
Erik

Script:
///////////////////////////////////////////////////////////
dim fso
dim obj
dim serverfile
dim clientfile
dim clientcopy

set fso=createobject("scripting.filesystemobject")
serverfile="U:\My Documents\QA Database.mdb"
clientfile=fso.getparentfoldername(wscript.scriptfullname) & "\QA Database(COPY).mdb"
clientcopy=fso.getparentfoldername(wscript.scriptfullname) & "\QA Database(COPY).ldb"
fso.copyfile serverfile,clientfile,true

set obj=createobject("access.application.11")
obj.automationsecurity=1
obj.opencurrentdatabase clientfile
obj.usercontrol=true

if fso.fileexists(clientfile) then
while fso.fileexists(clientcopy)
wend
fso.deletefile clientfile
end if
set fso=nothing
set obj=nothing
 
A starting point:
Code:
CreateObject("WScript.Shell").Run Chr(34) & clientfile & Chr(34), 3, True

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Thanks PHV. Is chr(34) ONLY used to wrap around location paths? All the examples I saw indicates that.

Also, I could not find any Access specific switches which would take care of the automationsecurity flag. So I assume the flag would need to be inserted into the run method somehow. Please point me in the right direction.

I tried:
CreateObject("WScript.Shell").Run Chr(34) & clientfile & Chr(34) & "automationsecurity=1", 3, True

That doesn't throw up any errors, but doesn't work either. Starting off the run method with that does cause an error. Is this even supported by wscript.shell, or do I have to use access.application as before?

Revised script(lines are now commented out):
//////////////////////////////////////////////////////////
dim fso
dim obj
dim serverfile
dim clientfile
dim clientcopy

set fso=createobject("scripting.filesystemobject")
serverfile="U:\My Documents\Copy of QA Database.mdb"
clientfile=fso.getparentfoldername(wscript.scriptfullname) & "\QA Database(COPY).mdb"
clientcopy=fso.getparentfoldername(wscript.scriptfullname) & "\QA Database(COPY).ldb"
fso.copyfile serverfile,clientfile,true

'set obj=createobject("access.application.11")
'obj.automationsecurity=1
'obj.opencurrentdatabase clientfile
'obj.usercontrol=true

createobject("wscript.shell").run chr(34) & clientfile & chr(34),3,true

'if fso.fileexists(clientfile) then
'while fso.fileexists(clientcopy)
'wend
fso.deletefile clientfile
'end if
set fso=nothing
set obj=nothing
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top