[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

FTP via Access 2000 VBA shell

Posted on 2006-04-04
9
Medium Priority
?
894 Views
Last Modified: 2008-02-01
I would like to import multiple files into a specific directory via ftp by executing an ftp script file inside VBA code.  

So I created a script file named A2006D.TXT:

PROMPT
OPEN {addres}
{user}
{password}
QUOTE SITE FILETYPE=JES
lcd W:\PerformanceMeasures\Monthly Reports
MGET S200602*.mdb
BYE

Then I created a batch file named A2006E.BAT:

cd W:\PerformanceMeasures\Monthly Reports
ftp -s:A2006E.TXT


If I run A2006E.BAT from command line, it executes fine.

But if I run it through shell, it fails.
                Dim cmdline As String
                cmdline = CurrentProject.Path & "\A2006E.BAT"
                Shell cmdline, vbMaximizedFocus

What is wrong with my code? Can you help me?

Thank you,






0
Comment
Question by:ornekm
  • 3
  • 3
  • 3
9 Comments
 
LVL 39

Expert Comment

by:thenelson
ID: 16373850
A batch file run in shell needs to have quotation marks around it:
                cmdline = "" & CurrentProject.Path & "\A2006E.BAT"""
0
 
LVL 39

Assisted Solution

by:thenelson
thenelson earned 1000 total points
ID: 16373855
You would also need the qoutation marks if CurrentProject.Path has spaces in it.
0
 

Author Comment

by:ornekm
ID: 16374158
I tried both of your suggestions.  Still nothing.
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 39

Expert Comment

by:thenelson
ID: 16374358
Put a code break on
              Shell cmdline, vbMaximizedFocus
put
?cmdline
in the immediate pane.  It should show
"<thePath>\A2006E.BAT"

You can also try
                cmdline = Chr(34) & CurrentProject.Path & "\A2006E.BAT" & Chr(34)

0
 
LVL 52

Accepted Solution

by:
Gustav Brock earned 1000 total points
ID: 16379110
You probably miss the command processor:

Public Sub RunFTP(ByVal strScriptFile As String)

' Usage Example:
'   call RunFTP("C:\temp\test.scr")
'
' Sample SCR File for NT/Win95 FTP
'   open someftpserver.com
'   anonymous
'   myaccount@myrealbox.com
'   lcd "c:\temp"
'   cd public
'   binary
'   prompt
'   mput *.jpg
'   get myfile.txt lastfile.txt
'   close
'   bye

  Dim strWinSysDir  As String
  Dim strQuote      As String
  Dim strMsgTitle   As String
  Dim strMsgPrompt  As String
  Dim lngMsgStyle   As Long
 
  strQuote = Chr(34)
  strMsgTitle = "FTP Transfer"
 
  If Len(strScriptFile) = 0 Then
    strMsgPrompt = "No script file specified." & vbCrLf & "Transfer cancelled."
    lngMsgStyle = vbCritical + vbOKOnly
    DoCmd.Beep
  Else
    If Len(Dir(strScriptFile)) = 0 Then
      strMsgPrompt = "Script file '" & strScriptFile & "' cannot be found." & vbCrLf & "Transfer cancelled."
      lngMsgStyle = vbCritical + vbOKOnly
      DoCmd.Beep
    Else
      strWinSysDir = Environ("COMSPEC")
      strWinSysDir = Left(strWinSysDir, Len(strWinSysDir) - Len(Dir(strWinSysDir)))
      strMsgPrompt = "Transfer in progress." & vbCrLf & "Press OK here when finished."
      lngMsgStyle = vbExclamation + vbOKOnly
      Call Shell(strWinSysDir & "ftp.exe -s:" & strQuote & strScriptFile & strQuote, vbNormalNoFocus)
    End If
  End If
 
  ' Pause here. Let the user wait for the FTP session to finish.
  MsgBox strMsgPrompt, lngMsgStyle, strMsgTitle

End Sub

/gustav
0
 

Author Comment

by:ornekm
ID: 16381884
It works for paths without spaces.  

As thenelson indicated I think the problem is with the spaces in the path info of the target script file.  How do I fix that?
0
 

Author Comment

by:ornekm
ID: 16381940
Okay.  I figured it out. Chr(34) additions saved the day.  Thank you all!
0
 
LVL 52

Expert Comment

by:Gustav Brock
ID: 16381982
As he wrote:

    cmdline = Chr(34) & CurrentProject.Path & "\A2006E.BAT" & Chr(34)

/gustav
0
 
LVL 52

Expert Comment

by:Gustav Brock
ID: 16382007
Oh, you think faster than I can write ...

/gustav
0

Featured Post

Free learning courses: Active Directory Deep Dive

Get a firm grasp on your IT environment when you learn Active Directory best practices with Veeam! Watch all, or choose any amount, of this three-part webinar series to improve your skills. From the basics to virtualization and backup, we got you covered.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Access developers frequently have requirements to interact with Excel (import from or output to) in their applications.  You might be able to accomplish this with the TransferSpreadsheet and OutputTo methods, but in this series of articles I will di…
In Part II of this series, I will discuss how to identify all open instances of Excel and enumerate the workbooks, spreadsheets, and named ranges within each of those instances.
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …

873 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question