Executing a DOS command from a module

dcarr

Trainee Database Analyst
Local time
Today, 16:04
Joined
Jun 19, 2002
Messages
112
Does anybody know the syntax for executing a DOS command from a MS Access module?
Thanks
 
does anyone know how to run a command once you have opened a dos window.
I have used shell(C:\windows\cmd.exe",1) to open the dos window, but need to run a command in that window from the same button as opened the dos window

as an example
the dir command
 
What are you trying to achieve?

You have the Dir Function available to you in Access.

Returns a String representing the name of a file, directory, or folder that matches a specified pattern or file attribute, or the volume label of a drive.

It can be used to create a list of files, if required.
 
What are you trying to achieve?

You have the dir function available to you in Access.



It can be used to create a list of files, if required.
I used dir as an example, I have a range of commands I wish to run to create txt files which will then be imported as tables into access.
I can do the rest of the process it is just sending the command to the dos session that is stumping me.
 
I used dir as an example, I have a range of commands I wish to run to create txt files which will then be imported as tables into access.
I can do the rest of the process it is just sending the command to the dos session that is stumping me.

There's a wealth of VBA commands to create / manipulate directories and files, including creating text files. I suggest you use these.

Otherwise try pseudocode:
Code:
dim objShell as Object
Set objShell = CreateObject("WScript.Shell")
strCommand = "cmd /c dir /s"
objShell.Run strCommand

Alternative:
Code:
    Set objFSO = CreateObject("Scripting.FileSystemObject")
    Set objLogFile = objFSO.CreateTextFile("C:\mytext.txt")
    
    With objLogFile
        .WriteLine "This is a Test"
        .WriteBlankLines (2)
        .WriteLine "FIN"
        .Close
    End With
 
Last edited:

Users who are viewing this thread

Back
Top Bottom