473,379 Members | 1,201 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,379 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 5454
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...
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...
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...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.