Microsoft Access VBA Macro Programming

(Tina Sui) #1
A true or false value is placed in the variable Chk by this process. If Chk is true, then the
file download was a success and the appropriate message is displayed. Otherwise, a failure
message is shown.
The Internet connections are closed using the API callInternetCloseHandle.
By using the API callFTPPutFile, files can be transferred from the local PC to the FTP
server, provided that your user ID has the necessary permissions. Here is the modified code:

Sub PutFile()
Dim MyConn, MyINet, Chk As Boolean

Chk = False
MyINet = InternetOpen("MyFTP", 1, vbNullString, vbNullString, 0 )
If MyINet > 0 Then

MyConn = InternetConnect(MyINet, "MyOrg.MyServer.net", 21, _
"MyUserID", _ "MyPassword", 1, 0, 0 )

If MyConn > 0 Then

Chk = FtpPutFile(MyConn, CurrentProject.Path & \test.txt", _
" MyFolder/MyFileName.txt", 1, 0 )
InternetCloseHandle MyConn
End If
InternetCloseHandle MyINet
End If

If (Chk) Then

MsgBox "File uploaded"
Else
MsgBox "FTP Error"
End If

End Sub

Use of Semaphore Files


In applications that use FTP code to transfer files, the files are often very large and can take
many minutes to transfer. The problem here is that the next stage of the process does not
know when the file is complete. If you use the FTP process to transfer a big file over, when
you look at the folder you will see the file is there almost immediately but with a very small
length. This then increases in size as the FTP transfer takes place.

340 Microsoft Access 2010 VBA Macro Programming

Free download pdf