Default value of file field

Hey Experts!!
I have an update page that has 4 fields that I wish to have populated with the value.  The problem is these are file fields and their default value will not populate so that when updating the images stay the same.  
I need a solution for this please.  I do not want to take the fields out of the form, but I do need to keep the images the same if they are not being updated.  I hope I explained that correctly
LVL 30
LZ1Asked:
Who is Participating?
 
R_HarrisonCommented:
The below should work if you enter the details where marked in CAPS.

This will only update if a file was uploaded, otherwise it will leave the database untouched.
Set theForm = Server.CreateObject("ABCUpload4.XForm")
Set theField = theForm("NAME-OF-YOUR-FILE-FIELD")(1)
REM ---- CHECK IF A FILE WAS UPLOADED ------------------
If theField.FileExists Then
    Set Conn = Server.CreateObject("ADODB.Connection")
    YOUR DATABASE CONNECTION GOES HERE
    Set rs = Server.CreateObject("ADODB.Recordset")
    rs.open "THE-TABLE-TO-UPDATE", Conn, 1, 2
    rs.filter = "A-DATABASE-FIELD=SOMETHING"
    rs("NAME-OF-FIELD-IN-DBASE").Value = theField.Data
    rs.Update
    rs.Close
    Conn.Close
End IF

Open in new window

0
 
R_HarrisonCommented:
On the page that does the updating you should check if a file has been submitted, if not do not update the field.  The exact command may vary depending on what you are using to upload but is usually something like... (this is for ABCUpload4)

if thefield.fileexists then .....  update the database as a file has been supplied

It is not possible to set default values for File fields as the would pose a major security problem as you could specify any file to be uploaded off a 'vistors' computer!!!
 
0
 
LZ1Author Commented:
Sorry it's taken so long to get back to you, but do you have a script or code sample I may be able to use?  Or have a place where I can find one?
0
 
LZ1Author Commented:
Thanks again!  After a little tweaking, it worked fine.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.