Solved

Default value of file field

Posted on 2008-10-08
4
183 Views
Last Modified: 2012-06-27
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
0
Comment
Question by:LZ1
  • 2
  • 2
4 Comments
 
LVL 12

Expert Comment

by:R_Harrison
ID: 22677563
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
 
LVL 30

Author Comment

by:LZ1
ID: 22706143
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
 
LVL 12

Accepted Solution

by:
R_Harrison earned 500 total points
ID: 22706471
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
 
LVL 30

Author Closing Comment

by:LZ1
ID: 31504531
Thanks again!  After a little tweaking, it worked fine.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

I would like to start this tip/trick by saying Thank You, to all who said that this could not be done, as it forced me to make sure that it could be accomplished. :) To start, I want to make sure everyone understands the importance of utilizing p…
I was asked about the differences between classic ASP and ASP.NET, so let me put them down here, for reference: Let's make the introductions... Classic ASP was launched by Microsoft in 1998 and dynamically generate web pages upon user interact…
In this video I am going to show you how to back up and restore Office 365 mailboxes using CodeTwo Backup for Office 365. Learn more about the tool used in this video here: http://www.codetwo.com/backup-for-office-365/ (http://www.codetwo.com/ba…
Many functions in Excel can make decisions. The most simple of these is the IF function: it returns a value depending on whether a condition you describe is true or false. Once you get the hang of using the IF function, you will find it easier to us…

863 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

Need Help in Real-Time?

Connect with top rated Experts

24 Experts available now in Live!

Get 1:1 Help Now