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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

FTP OPTION

Status
Not open for further replies.

jedel

Programmer
Jan 11, 2003
430
AU
Hey, I've integrated the FTP Code created by 1DMF (Found is FAQs) into my database which is working great. I need to upload two separate files though. What I have done is bound the FTP Form to a table and placed two records in the table, each with different file names and different URL locations.

However I can't seem to get it to work. I tried moving through the records by opening a record set to the table and looping through the records using While and Wend, but it doesn't recognised the FTPFile function and come up with an error; "Argument not optional"

Any suggestions on how I can upload two files using the FTP code in the FAQ by 1DMF?

Here is the code snippet attached to the button, the module is working fine:
Code:
Private Sub Command16_Click()
On Error GoTo Err_Upload_Click
Dim db As Database
Dim rs As Recordset

Me.lblLink.Caption = "Uploading Database, please wait..."
Me.lblLink.Visible = True

Set db = CurrentDb
Set rs = db.OpenRecordset("FTPTbl", dbOpenDynaset)

With rs
.MoveLast
.MoveFirst
While Not .EOF

' Check for Selected file
If Nz(!FileName, "") = "" Then
    MsgBox "Please select file to upload first!"
    Exit Sub
End If

' Check for FTP Server
If Nz(!domain, "") = "" Then
    MsgBox "Please enter FTP Domain!"
    Exit Sub
End If

' Check for UserName
If Nz(!UserName, "") = "" Then
    MsgBox "Please enter User Name!"
    Exit Sub
End If

' Check for Password
If Nz(!pword, "") = "" Then
    MsgBox "Please enter Password!"
    Exit Sub
End If

' Set Default upload directory to root if nothing supplied
If Nz(!Directory, "") = "" Then
    Me!ServerDir = "/"
    Me.Refresh
End If

' Upload file
If FTPFile(!domain, !UserName, !pword, !FileName, !Directory, !tfrmode) Then
    'MsgBox "Upload - Complete!"
End If
.MoveNext
Wend
End With
Set rs = Nothing
Set db = Nothing


Exit_Upload_Click:
    Exit Sub

Err_Upload_Click:
    MsgBox "Error in Upload_Click : " & Err.Description
    Resume Exit_Upload_Click
End Sub

Cheers

Dean

-------------------------------------------------------------
"The most overlooked advantage of owning a computer is that if they foul up there's no law against whacking them around a bit."
 
error; "Argument not optional"
The function requires 7 parameters and you call it with only 6.

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Thanks PHV, I saw that one. After a number of other issues, I finally managed to get the code to work through the While Wend loop. It was when I saved the filename of the excel spreadsheet into a record, I didn't include the File extension, therefore the code could not find the second file to upload.

I do have one more snippet I want to add to this masterpiece and that is adding another record to a table with two fields; one filed will contain the month value in the combo box and the other will contain the filename.

I have no problems with adding this data into the table. What don't want to happen if for two of the same record to be added. So, Can yoy help me with a piece of code that looks for a record in a table BEFORE deciding to add it?

Here is what I will use for adding the data to the table

Code:
dim db as Database
Dim rs as Recordset

Set db = CurrentDB
Set rs = db.openrecordset("DLRosterTBL", dbOpenDynaSet)

with rs
.addNew
!dtemonth = me.cboMonth
!Filename = Me.cboMonth & "Roster" & Format(Date, "yyyy") & ".xls"
.update
end With

Set db =nothing
set rs = nothing

I was thinking of an if then statement, but I'm not sure on how to look for a record in the table.

Cheers

Dean


-------------------------------------------------------------
"The most overlooked advantage of owning a computer is that if they foul up there's no law against whacking them around a bit."
 
Have a look at the DLookUp function.

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
PHV,

Not quite what I was looking at but I'll run with it. I need the Dlookup to return a null value in order to add a new record. Problem i'm having with it is that it always returns a null value.

Here's the code:

Code:
If IsNull(DLookup("dteMonth", "DLRosterTBL", dteMonth = Me.cboMonth)) Then

With rs

.AddNew
!dteMonth = Me.cboMonth
!FileName = Me.cboMonth & "Roster" & Format(Date, "yyyy") & ".xls"
.Update
End With

Set db = Nothing
Set rs = Nothing
Else
End If

What am I doing wrong?

-------------------------------------------------------------
"The most overlooked advantage of owning a computer is that if they foul up there's no law against whacking them around a bit."
 
PHV

Not to worry, I found it!

here's the code that worked:
Code:
If IsNull(DLookup("dteMonth", "DLRosterTBL", "dteMonth = '" & Me.cboMonth & "'")) Then

With rs

.AddNew
!dteMonth = Me.cboMonth
!FileName = Me.cboMonth & "Roster" & Format(Date, "yyyy") & ".xls"
.Update
End With

Set db = Nothing
Set rs = Nothing
Else
End If

Thanks of rmaking t hink outside the square.

Cheers

Dean

-------------------------------------------------------------
"The most overlooked advantage of owning a computer is that if they foul up there's no law against whacking them around a bit."
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top