Closing DOS window - reposting

  • Thread starter Thread starter Mark
  • Start date Start date
M

Mark

Perhaps there's not a way to do this, but I thought I'd post once more ...

I'm looking for a way to programmatically close a DOS window after shelling
out to Pkzip (DOS ver.). This is on a local machine, Win98, Access97, but
I'll also want to do it on a local WinXP, Access2002 machine.

After Pkzip finishes processing, I'm not actually at a command prompt, so
sending "exit" doesn't close the window. Alt-F4 does close it. Do I use
"SendKeys"? If so, could someone please help me with the syntax? Also, I'm
concerned about the timing -- allowing Pkzip to finish processing before
attempting to close the DOS window.

What I have thus far is:

Private Sub Command55_Click()

Dim zipname, cmdstring, foo

zipname = "fpsdata" & ".zip"

cmdstring = "C:\pkzip\pkzip -xc:\access97 a:\" & zipname _
& " c:\access97\fpsdata.mdb"
DoCmd.Close

foo = Shell(cmdstring, 1)

End Sub

p.s. What is the purpose of "DoCmd.Close" in this procedure?

Thank you.
Mark.
 
would it not be easier to create a batch file:

REM Start of Batch File
C:\pkzip\pkzip -xc:\access97 a:\fpsdata.zip c:\access97\fpsdata.mdb
exit
REM End of Batch File

and run it using the shell function?

P
 
I think you're right. Thanks Phobos.
Phobos said:
would it not be easier to create a batch file:

REM Start of Batch File
C:\pkzip\pkzip -xc:\access97 a:\fpsdata.zip c:\access97\fpsdata.mdb
exit
REM End of Batch File

and run it using the shell function?

P
 
Whether you use a batch file or not, you will still have to use the "wait
for single process" API call to ensure the zip processing is finished,
before carrying on with the rest of your code.

Look up the procedure from www.allapi.com

Very briefly, something like this:

plot = "Your command string"

DoEvents
PID = Shell(plot)

If PID = vbEmpty Then
'
'Handle Error, Shell Didn't Work
'
MsgBox ("Shell failed")

Else
hProcess = OpenProcess(&H100000, True, PID)
WaitForSingleObject hProcess, -1
CloseHandle hProcess
End If


and you need these declarations in a code module:
Declare Function OpenProcess _
Lib "kernel32" _
(ByVal dwDesiredAccess As Long, _
ByVal bInheritHandle As Long, _
ByVal dwProcessId As Long) As Long

Declare Function CloseHandle _
Lib "kernel32" _
(ByVal hObject As Long) As Long

Declare Function WaitForSingleObject _
Lib "kernel32" _
(ByVal hHandle As Long, _
ByVal dwMilliseconds As Long) As Long
--
Regards,

Adrian Jansen
J & K MicroSystems
Microcomputer solutions for industrial control
 
p.s. What is the purpose of "DoCmd.Close" in this procedure?

It closes the active form - the form with the btn you
just clicked (command55).

By longstanding practice, we use

docmd.close acform, me.name

which almost always means the same thing.

(david)
 
david epsom dot com dot au said:
It closes the active form - the form with the btn you
just clicked (command55).

By longstanding practice, we use

docmd.close acform, me.name

which almost always means the same thing.

(david)
 
Thanks Adrian. ?www.allapi.com? -- kind of overwhelming, but you're code
helps and I think I remember seeing something about this either in the
Developer's Handbook, or on one of the Access-support web sites.
 
Back
Top