simple dir call

P

punjab_tom

hello.. my name is Tom. I am new here; I just started with access.

I want to find out what I am doing wrong with this code... I want to
launch a DOS window with a filter on DIR to give me a list - in DOS- of
the correct files.

When I take this command into a BAT file it works great.. only when I
send it to the SHELL command in Access does it give me trouble.. it
only says '53 - file not found'

When I stop it through this and i check strShell it gives me this

?strShell
DIR "C:\TOM\RDL\*disenrollment*.RDL" /B


Thank you for your patience

Tom



--------------------------------
Private Sub cmdFind_RdlPath_Click()
On Error GoTo errHandler

Dim strShell As String

strShell = "DIR " & Chr(34) & "C:\TOM\RDL\*" &
Trim(GetLongestWord(Me.LetterFormName)) & "*.RDL" & Chr(34) & " /B"
Call Shell(strShell, vbNormalFocus)



cleanExit:
Exit Sub
errHandler:
MsgBox Err.Number & " - " & Err.Description, vbOKOnly
Resume Next
End Sub
 
D

Dirk Goldgar

hello.. my name is Tom. I am new here; I just started with access.

I want to find out what I am doing wrong with this code... I want to
launch a DOS window with a filter on DIR to give me a list - in DOS-
of the correct files.

When I take this command into a BAT file it works great.. only when I
send it to the SHELL command in Access does it give me trouble.. it
only says '53 - file not found'

When I stop it through this and i check strShell it gives me this

?strShell
DIR "C:\TOM\RDL\*disenrollment*.RDL" /B


Thank you for your patience

Tom



--------------------------------
Private Sub cmdFind_RdlPath_Click()
On Error GoTo errHandler

Dim strShell As String

strShell = "DIR " & Chr(34) & "C:\TOM\RDL\*" &
Trim(GetLongestWord(Me.LetterFormName)) & "*.RDL" & Chr(34) & " /B"
Call Shell(strShell, vbNormalFocus)



cleanExit:
Exit Sub
errHandler:
MsgBox Err.Number & " - " & Err.Description, vbOKOnly
Resume Next
End Sub

Since the Dir command is a built-in command, you have to shell to
"cmd.exe" or "command.com" and pass the command line as an argument.
Somthing like this:

Shell "cmd.exe /K " & Chr(34) & strShell & Chr(34), vbNormalFocus
 
P

punjab_tom

are there other functions that have the same problem?

for example; if i have a VBA function named 'GetFiles' and I have an
EXE named 'GetFiles' in my path / system directory.. will VBA always
cause problems??

does this happen in vb6 or is it just in VBA?

it seems like this is using callbyname or something
 
D

Douglas J. Steele

Using Shell should mean that the VBA function will be ignored.

I believe what Dirk meant was that Dir is a built-in DOS command, therefore
you need to provide it an environment in which to run (which is what cmd.exe
or command.exe provides).
 
D

Dirk Goldgar

are there other functions that have the same problem?

for example; if i have a VBA function named 'GetFiles' and I have an
EXE named 'GetFiles' in my path / system directory.. will VBA always
cause problems??

does this happen in vb6 or is it just in VBA?

it seems like this is using callbyname or something

No, that's not what I meant by "built-in command" -- though it's true
that Dir is a built-in VBA function, that's not the cause of the
problem. What I meant is that "Dir" is not an executable file. There
is no "Dir.exe" or "Dir.com", so you can't shell to it directly. The
command "Dir" is built into the Windows command interpreter, so you have
to invoke the command interpreter -- "cmd.exe" -- and pass it the name
of the command "Dir", along with any additional arguments, to be
executed.
 

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

Top