Search:     Advanced search
Browse by category:
Glossary | Contact Us

Database Knowledge Base / MS Access /

How do I run an internal DOS command from within Access Basic, if I try x=Shell("copy file1 file2",1) I get a message "File not found".

Add comment
Views: 195
Votes: 1
Comments: 0
DOS internal commands are processed by the command processor shell so you should be calling this program and not trying to execute the internal command itself.

The command processor is usually command.com but this can vary and so can it's location (indeed it can even reside outside of the dos search path) for this reason it's not a good idea to hard code it's location or name into an application as this may change if the application is moved to another pc. Use the Environ function to retrieve the %COMSPEC% environment variable as this always points to the current command processor shell. e.g.

Dim hTask As Integer
hTask = Shell(Environ("COMSPEC") & " /C COPY file1 file2", 1)

Note: Some of the DOS internal commands are available in Access Basic (in the long form of the command), e.g. RmDir, ChDir, MkDir. The Dir command can be emulated using the Dir() function although this only returns files, not hidden/system files or directory names.
Others in this Category
document When compacting an Microsoft Access database how do you control the ownership of the database?
document How can I make my combo and list boxes faster?
document Where can I obtain a list of Access Basic Errors and their associated messages
document How do I access the recordset of a SUBform. I know how to clone the set of a form, but this doesn't work for subforms.
document How do I emulate the "Record X of Y" that Access displays in the navigation buttons
document How we can perform MINUS (Oracle) Or EXCEPT (Maxdb) in MS Access?
document What is Data Mapping
document What is an Ad Hoc Query?



RSS