473,326 Members | 2,095 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,326 software developers and data experts.

Upload file and save it in database (Access 2003)

kev
Hi folks,

I have created a database to store information on equipments. During
the first level of registration, there is a form that i need the user
to fill up details on the equipment testing. i have done this one.Now
what i need is to enable the users to upload files and save it into the
corresponding table.

Example: 3. A laser inventory form has been completed for each 3b or
4 laser and submitted to the Laser Safety Officer (LSO)? which requires
users to answer whether Passed or Not Applicable in a combo box.
If the answer is "Passed", i need the users to upload the "Laser
inventory form".
If the answer is "Not Applicable", then there is no action, users
simply move on to another control on the same form.

My second question is what fields and what data type must i must create
in the underlying table"SafetyLevel1"?

Appreciate if someone could offer help on this plus specific details
(coding and where to attach it--which event). I really need it urgently
coz the deadline is just around the corner. Please help.

Great thanks.

Dec 13 '06 #1
4 5449
On 12 Dec 2006 18:32:49 -0800, "kev" <ke******@gmail.comwrote:

Your questions are confusing to me.
You write "...enable the users to upload files and save it into the
corresponding table..."
What do you mean - upload files. I'm assuming you are speaking of an
Access application. "upload files" is more commonly used term in the
context of a web application. On the LAN (where Access operates) we
don't "upload" files. Perhaps we enter a filename in a textbox or find
it using a File>Open dialog.

Then later you write"i need the users to upload the "Laser
inventory form""
So now we're uploading a form rather than a file? What does that mean:
"uploading a form"?

Use precise language, and we might be able to help.

-Tom.
>Hi folks,

I have created a database to store information on equipments. During
the first level of registration, there is a form that i need the user
to fill up details on the equipment testing. i have done this one.Now
what i need is to enable the users to upload files and save it into the
corresponding table.

Example: 3. A laser inventory form has been completed for each 3b or
4 laser and submitted to the Laser Safety Officer (LSO)? which requires
users to answer whether Passed or Not Applicable in a combo box.
If the answer is "Passed", i need the users to upload the "Laser
inventory form".
If the answer is "Not Applicable", then there is no action, users
simply move on to another control on the same form.

My second question is what fields and what data type must i must create
in the underlying table"SafetyLevel1"?

Appreciate if someone could offer help on this plus specific details
(coding and where to attach it--which event). I really need it urgently
coz the deadline is just around the corner. Please help.

Great thanks.
Dec 13 '06 #2
kev
Hi Tom,

I am sorry for the confusing mail. What i need is for the users to
search/find for a file (perhaps saved in their own hard disk) and
later save it in the corresponding table"SafetyLevel1".
What i meant by file is Microsoft Word or Excel files.

I use the wrong word it's not form it's a file.
Hope you understood my request and thanks in advance for your help.

Tom van Stiphout wrote:
On 12 Dec 2006 18:32:49 -0800, "kev" <ke******@gmail.comwrote:

Your questions are confusing to me.
You write "...enable the users to upload files and save it into the
corresponding table..."
What do you mean - upload files. I'm assuming you are speaking of an
Access application. "upload files" is more commonly used term in the
context of a web application. On the LAN (where Access operates) we
don't "upload" files. Perhaps we enter a filename in a textbox or find
it using a File>Open dialog.

Then later you write"i need the users to upload the "Laser
inventory form""
So now we're uploading a form rather than a file? What does that mean:
"uploading a form"?

Use precise language, and we might be able to help.

-Tom.
Hi folks,

I have created a database to store information on equipments. During
the first level of registration, there is a form that i need the user
to fill up details on the equipment testing. i have done this one.Now
what i need is to enable the users to upload files and save it into the
corresponding table.

Example: 3. A laser inventory form has been completed for each 3b or
4 laser and submitted to the Laser Safety Officer (LSO)? which requires
users to answer whether Passed or Not Applicable in a combo box.
If the answer is "Passed", i need the users to upload the "Laser
inventory form".
If the answer is "Not Applicable", then there is no action, users
simply move on to another control on the same form.

My second question is what fields and what data type must i must create
in the underlying table"SafetyLevel1"?

Appreciate if someone could offer help on this plus specific details
(coding and where to attach it--which event). I really need it urgently
coz the deadline is just around the corner. Please help.

Great thanks.
Dec 13 '06 #3
On 12 Dec 2006 22:14:44 -0800, "kev" <ke******@gmail.comwrote:

It is unusual to save a file in a table. Is that really what you want
to do? Why?
More commonly files would be copied to a central network location,
accessible to all users. The table would only contain a string with
the path to the file.

Allowing users to search/find a file is typically done using a
File/Open dialog. Check this out:
http://www.mvps.org/access/api/api0001.htm
and bookmark that site!

-Tom.
>Hi Tom,

I am sorry for the confusing mail. What i need is for the users to
search/find for a file (perhaps saved in their own hard disk) and
later save it in the corresponding table"SafetyLevel1".
What i meant by file is Microsoft Word or Excel files.

I use the wrong word it's not form it's a file.
Hope you understood my request and thanks in advance for your help.

Tom van Stiphout wrote:
>On 12 Dec 2006 18:32:49 -0800, "kev" <ke******@gmail.comwrote:

Your questions are confusing to me.
You write "...enable the users to upload files and save it into the
corresponding table..."
What do you mean - upload files. I'm assuming you are speaking of an
Access application. "upload files" is more commonly used term in the
context of a web application. On the LAN (where Access operates) we
don't "upload" files. Perhaps we enter a filename in a textbox or find
it using a File>Open dialog.

Then later you write"i need the users to upload the "Laser
inventory form""
So now we're uploading a form rather than a file? What does that mean:
"uploading a form"?

Use precise language, and we might be able to help.

-Tom.
>Hi folks,

I have created a database to store information on equipments. During
the first level of registration, there is a form that i need the user
to fill up details on the equipment testing. i have done this one.Now
what i need is to enable the users to upload files and save it into the
corresponding table.

Example: 3. A laser inventory form has been completed for each 3b or
4 laser and submitted to the Laser Safety Officer (LSO)? which requires
users to answer whether Passed or Not Applicable in a combo box.
If the answer is "Passed", i need the users to upload the "Laser
inventory form".
If the answer is "Not Applicable", then there is no action, users
simply move on to another control on the same form.

My second question is what fields and what data type must i must create
in the underlying table"SafetyLevel1"?

Appreciate if someone could offer help on this plus specific details
(coding and where to attach it--which event). I really need it urgently
coz the deadline is just around the corner. Please help.

Great thanks.
Dec 13 '06 #4
Howdy,

I think I know what you are after, so I hope this helps:

1/ Use the common dialog control to allow a user to hunt for a file.

2/ once you know what the path/filename is then you can insert it into
the database.

The type of field that you require is a dbLongBinary field, also called
an OLE field by Access.

The most efficient way to load data into a dbLongBinary field is to use
"BLOB" type loading. I have included the code below to both load a
file, as a BLOB, into a field, and also in turn to extract a file from
a BLOB record back to a file.

The word of warning that goes with this is that in order to see the
contents of the file you must first extract it from the record and back
to a file, then open the file/document. You are unable to read the file
directly when it is a BLOB.

The advantage of BLOB's is that they are very efficient when storing
data, much more so than using simple OLE types which eat a lot of space
in the DB.

I hope this helps, code is below

Cheers

The Frog

This is the code to extract a BLOB back to being a file...

Sub BlobToFile(fld As ADODB.Field, filename As String, _
Optional ChunkSize As Long = 8192)
Dim fnum As Integer, bytesLeft As Long, bytes As Long
Dim tmp() As Byte

' Raise an error if the field doesn't support GetChunk.
If (fld.Attributes And adFldLong) = 0 Then
Err.Raise 1001, , "Field doesn't support the GetChunk method."
End If
' Open the file;, delete it firstoverwrite it if necessary.' Delete
the
' file if it exists already, then create a new one.
If Dir$(filename) <"" Then Kill filename

fnum = FreeFile
Open filename For Binary As fnum
' Read the field's contents, and write it the data to the file.
bytesLeft = fld.ActualSize

Do While bytesLeft
bytes = bytesLeft
If bytes ChunkSize Then bytes = ChunkSize
tmp = fld.GetChunk(bytes)
Put #fnum, , tmp
bytesLeft = bytesLeft - bytes
Loop

Close #fnum
End Sub
and this is the code to take a file and make it a BLOB and store it
somewhere in the DB

Sub FileToBlob(fld As ADODB.Field, filename As String, Optional
ChunkSize As Long = 8192)

Dim fnum As Integer, bytesLeft As Long, bytes As Long
Dim tmp() As Byte

' Raise an error if the field doesn't support GetChunk.
If (fld.Attributes And adFldLong) = 0 Then
Err.Raise 1001, , "Field doesn't support the GetChunk method."
End If

' Open the file; raise an error if the file doesn't exist.
If Dir$(filename) = "" Then Err.Raise 53, , "File not found"

fnum = FreeFile
Open filename For Binary As fnum

' Read the file in chunks, and append data to the field.
bytesLeft = LOF(fnum)
Do While bytesLeft
bytes = bytesLeft
If bytes ChunkSize Then bytes = ChunkSize
ReDim tmp(1 To bytes) As Byte
Get #1, , tmp
fld.AppendChunk tmp
bytesLeft = bytesLeft - bytes
Loop

Close #fnum

End Sub
you need to make a reference to the ADO and ADOX libraries before this
will work. (Tools/references -tick the box next to one of the ADO
versions (preferabley the latest one) and also the ADOX)

Dec 14 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: dave | last post by:
Hello there, I am at my wit's end ! I have used the following script succesfully to upload an image to my web space. But what I really want to be able to do is to update an existing record in a...
4
by: Mattias | last post by:
Hi I am building a simple database system in MS Access 2002 and would like to create a command button that upon clicking transfers the current mdb-file to an ftp-server. Is there a solution for...
0
by: SEMIH DEMIR | last post by:
Sitelerden birinde verilen yabancı kaynakli bir scriptti duzenledim yanlız birseyin içinden bir turlu cıkamadım işin aslı ilk defa persistin upload componentini kullanacam yanlız suanki haliyle...
9
by: Wayne Smith | last post by:
I've come up against a major headache that I can't seem to find a solution for but I'm sure there must be a workaround and I would really be grateful of any help. I'm currently building a web...
3
by: Stephan | last post by:
Hi all, I am new to access and I face the following "issue": I would like to create a database, to which users can upload files (=pdf, doc, xls...). The files shall be stored locally on a...
0
by: dann2 | last post by:
hello, i try to upload in an access db two pictures at the same time. i use the adjusted sample code from persits. it looks like this: ... '<% ' Create an instance of AspUpload object 'Set...
9
by: saldandm | last post by:
I think this is probably some minor oversight on my end but I'm just missing it. I have a multipart/form-data form in a ASP page. Inside the form I have traditional text fields and a upload field...
2
by: hotflash | last post by:
Hi All, I found the best pure ASP code to upload a file to either server and/or MS Access Database. It works fine for me however, there is one thing that I don't like and have tried to fix but...
6
by: lily86 | last post by:
i'm using vs.net 2003.... i want to let the user upload images and i want to save the image to my web server file to convenient i display the images on other pages.... but i'm having a problem when i...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.