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

chose unique file name 1

Status
Not open for further replies.

jslmvl

Vendor
Jan 26, 2008
268
GB
Hi,

In the same time, my web receives a text and a picture. As a record, the text will be put into access database while, as a file, the picture will be saved under a folder.
My question is how to chose file name for the picture so that they are unique and related to that record?

Thank you in advance.
 
you can make the text part of the file name and attach mili-seconds to the end of the file name, so each time it will be different and will match the text. just a thought.
 
What about....

Add an AutoNumber column to the table. Then...

Insert in to the table.
Retrieve the AutoNumber value (Using @@Identity).
Name the file something like.... File + (AutoNumberValue)



-George

"The great things about standards is that there are so many to choose from." - Fortune Cookie Wisdom
 
I don't think @@Identity works in Jet databases. I found this code at

Code:
<% 

Dim oRec 
Dim sConStr 
Dim sNewID 

sConStr = "your connection string here." 
Set oRec = Server.CreateObject("ADODB.RECORDSET") 
oRec.CursorLocation = adUseServer 

with oRec 
.Open "tblMyTableName",sConStr,adOpenKeySet,adLockOptimistic,adCmdTableDirect 
.AddNew 
.Fields("MYCOLUMNNAME") = "stuff" 
.Update 
sNewID = .Fields("MYIDENTITYCOLUMN") 
End With 

oRec.close 
Set oRec = nothing 

%>
sNewID returns the value of the of autonumber for the record just entered (using the AddNew...Update method just above it). That way you don't have to make the connection twice.

Paul
 
I don't think @@Identity works in Jet databases.

I beg to differ.


Article ID: 232144 - Last Review: [!]December 3, 2003[/!] - Revision: 3.1

By using an identity column (which MUST be unique), you can guarantee that the file name will be unique too.


-George

"The great things about standards is that there are so many to choose from." - Fortune Cookie Wisdom
 
Sorry, I was not 100% sure it wouldn't, but had seen stuff like this

There are some limitations you may encounter here, especially if you're used to the power of SQL Server.
Output parameters cannot be used.
[blue]Don't use the @ character. The @ character is often used in Transact SQL (SQL Server), where it represents a local variable. Access doesn't always convert this character and will sometimes leave it out. This can cause esoteric bugs which can lead to premature hair loss.[/blue]
Temporary tables are not available in Access.
[blue]I suspect many of the options available in Transact SQL are not available in Access as it's not Transact SQL compatible.[/blue]
which I had seen here

Thanks for the clarification.

Paul
 
place and rename the file first then carry that variable into the database record, and for less workload on a data server, i prefer to use commonly available values that will generally generate a unique value, and for general C.Y.A do a FSO.FileExists to ensure the almost possible unique value hasn't been used before.. one example would be to use session.sessionID + (timestamp or ticks of timestamp or random generators)

[thumbsup2]DreX
aKa - Robert
if all else fails, light it on fire and do the happy dance!
" I always think outside the 'box', because I'm never inside the 'loop' " - DreX 2005
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top