Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Shaun E on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Maybe a better way?

Status
Not open for further replies.

PeasNCarrots

Programmer
Jun 22, 2004
73
US
I am always looking to improve my code so I would like to ask anyone if the following code is efficient or can it be improved?

Sub GetGD2Data()

Dim arrTableNames(5) As String
Dim strFileExt As String
Dim iArray As Integer
Dim objFTP As FTP
Dim conTarget As String

arrTableNames(0) = "SUMMARY"
arrTableNames(1) = "DISPATCH"
arrTableNames(2) = "PACKAGE"
arrTableNames(3) = "STOPSUM"
arrTableNames(4) = "LABEL"
arrTableNames(5) = "TIM1"
arrTableNames(6) = "CENTER"

strFileExt = ".DBF"

'Download New Tables from FTP to local folder
Open AppPath & "\ftpcommand.ftp" For Output As #1
Print #1, ; "open manorwks0083"
Print #1, ; "anonymous"
Print #1, ; "anonymous"

For i = 0 To 6
Print #1, ; "get GD2Data/YesterDay/" & _
arrTableNames(i) & strFileExt & " " & """" & _
AppPath & "\Send Again\" & arrTableNames(i) & strFileExt & """"
Next

Print #1, ; "bye"
Close #1 ' Close file.

sleep 1500

'get the table
FTPFile "'" & AppPath() & "\ftpcommand.ftp'"

For i = 0 To 6
' Delete Tables to allow for new import
DoCmd.DeleteObject acTable, arrTableNames(i) & "_TEMP"

'Import new Tables
DoCmd.TransferDatabase acImport, "dbase 5.0", _
"D:\Documents and Settings\bos1bsc\My Documents\Send Again\", _
acTable, arrTableNames(i) & strFileExt, arrTableNames(i) & "_TEMP"

Next
End Sub
 
PeasNCarrots, your code is a little (or a lot), beyond my comprehension, at present, but, if I'm correct, you declared a 6 element array,
Dim arrTableNames(5) As String

but gave it 7?

arrTableNames(0) = "SUMMARY"
arrTableNames(1) = "DISPATCH"
arrTableNames(2) = "PACKAGE"
arrTableNames(3) = "STOPSUM"
arrTableNames(4) = "LABEL"
arrTableNames(5) = "TIM1"
arrTableNames(6) = "CENTER"

all your loops, loop 7 times.

Shouldn't this cause an "out of range" error?

Is your initial declaration wrong(typo).
I assume your code works fine, since that's not your question.

Ignore, if I'm off.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top