Keep Cmd Window ON TOP when using Shell Environ$("COMSPEC") cmd ??

  • Thread starter Thread starter kev100 via AccessMonster.com
  • Start date Start date
K

kev100 via AccessMonster.com

I've got a button on a form that, when clicked, needs to copy all the files
from a certian directory on the network to the local drive.

There is a text box on that form that contains the Name of the Network
Directory in which those files are stored.

The below code is the EVENT in the button's OnClick:

Dim CopyCmd As String

CopyCmd = "xcopy F:\NameData\" & [Forms]![MyForm]![DirTxtBox] & "\*.* /y
C:\LocalNameData\"

Shell Environ$("COMSPEC") & " /k " & CopyCmd


This works fine.....all files are copied (there are usually about 3) from the
network to the local drive.

However, while the CMD window does remain open (with the /k switch) it is
Minimized at the bottom.

It needs to not only remain open....but to be On TOP. The user needs to see
which files copied (if any). Sometimes there is a problem copying the files..
.and the user needs that visual feedback.


If there is some other way (like in a regular Windows GUI pop-up window)....
to provide this visual feedback of the files copied.....that would be fine
too.


Any advice appreciated.
THANKS
 
Have you looked at Help for the Shell function?

I've got a button on a form that, when clicked, needs to copy all the files
from a certian directory on the network to the local drive.

There is a text box on that form that contains the Name of the Network
Directory in which those files are stored.

The below code is the EVENT in the button's OnClick:

Dim CopyCmd As String

CopyCmd = "xcopy F:\NameData\" & [Forms]![MyForm]![DirTxtBox] & "\*.* /y
C:\LocalNameData\"

Shell Environ$("COMSPEC") & " /k " & CopyCmd


This works fine.....all files are copied (there are usually about 3) from the
network to the local drive.

However, while the CMD window does remain open (with the /k switch) it is
Minimized at the bottom.

It needs to not only remain open....but to be On TOP. The user needs to see
which files copied (if any). Sometimes there is a problem copying the files..
and the user needs that visual feedback.


If there is some other way (like in a regular Windows GUI pop-up window)....
to provide this visual feedback of the files copied.....that would be fine
too.


Any advice appreciated.
THANKS
 
John said:
Have you looked at Help for the Shell function?


I'm using Access 2002 . The F1 help lists zilch for "shell"....nothing comes
up....

I found a list of parameters yesterday....but none involved controlling if
the Window appeared On TOP.

...the /k or /c parameters control if the command window stays OPEN after the
command is complete (or not)....but not How the windows displays.

Is this something that would be better done using VB code?

Thanks
 
kev100 via AccessMonster.com said:
I'm using Access 2002 . The F1 help lists zilch for
"shell"....nothing comes up....

Because of the way the help system is split between Access help and VBA
help, you need to check it in the VB Editor window. If you do, you'll
see that the Shell function has an optional second argument,
"windowstyle", that deterimines the style of the window in which the
shelled application will be run. The default is default is to run it
minimized, but you could write:

Shell Environ$("COMSPEC") & " /k " & CopyCmd, _
vbNormalFocus

to run it restored with the focus. That won't force it to *stay* on
top, if the user clicks away, but it will start there.

Or, of course, you could get the list of files, display it on a form,
copy them yourself in code using the FileCopy statement, and display the
running result on the form -- bypassing the use of Shell altogether, at
the expense of a bit more programming work.
 
That won't force it to *stay* on
top, if the user clicks away,

About only way I can imagine of achieving that is to use API calls to
make the CMD.EXE window system modal (or maybe somehow turn it into a
child of the Access application window).
but it will start there.
Or, of course, you could get the list of files, display it on a form,
copy them yourself in code using the FileCopy statement, and display the
running result on the form -- bypassing the use of Shell altogether, at
the expense of a bit more programming work.

This may be the best way to go...
 
Shell Environ$("COMSPEC") & " /k " & CopyCmd, _
vbNormalFocus


Adding the vbNormalFocus does the trick.

The box stays open until it is x'd out.

Thanks very much.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top