hello everybody,
im venkat doing my b.e 3rd year... Im currently working on my project of college administration system using vb6.
I need help on how to save an image in the access database...i have got the code on how to browse an image. but i'm not able to find out how to save it to a particular record on a database.
So please help me in this,,thanx in advance
[/B]

Recommended Answers

All 16 Replies

Do you want to save the file name or the image?

Your question is unclear for the purpose of your request.

If you want to have the image to show in the form, you can only do it from a file so LoadPicture() the image to the form preferable to a frame or other picture object to store the image.

i need to save the image file...that is, if i register a new name i'll be having a option for photo uploading in the same form itself,,,,i need to save that photo by browsing the computers folders just like how we upload files, and after choosing a image file i need to save it to the particular record itself,,,im not talking about the name of the image but im talking about saving the image itself, So if we search for that name i'l be getting all his details including a photo....i hope u understand,,,

You mean you want to load the picture into the form?

LoadPicture will do this but like I say, VB6 only accepts *.bmp, *.gif, *.jpg but not other formats. It might accepts *.tif images but am not sure.

Still not sure about what you say. Saving is not the correct term to use. You either load the picture into a userform or you add the filename to the record for referencing.

Perhaps you want to copy the image file into your own folder?

You cannot put a file into a record. A record is just a data file that lists your data.

There is a means to store the image, but I have never attempted that.
You could end up with a rather large DB.
Why not create a sub folder in the same location as the DB.
Then have sub folders for each ID (Student ID ?)
Place the image in there.
Your program can retrieve the image any time in the future, as the program knows where to find the folder, and it knows the Student ID to locate that Student's sub folder.

RobCr - thanks for your input. I actually hate Access but know a bit about VB6.

venkatnams - RobCr says it can be done but it may bloat your database. I suggest if it is for student ID cards, to put the images into a sub folder then "Call each image as you need it into a form. Add Stuednt details to the form then print the ID Card (if this is the purpose of the project).

plz try it.

Chambutton.ocx? I've never heard of that. Did you create it yourself?

Data1.Recordset.AddNew - What does Data1 refer to?

Are you trying to access an Accesss database from outside of Access?
Access has it's own userform facility where you can access the database. I think you need an Sql event to open the database. I also think that if the user does not actually have Acess on the computer, accessing the mdb file will be hard to do as I believe that you can only acceess the file if the user has the software that created the file in the first place. Unless you are savvy to extracting data from a file, this is a hard task project.

try the following code, make changes as desired

Dim CN As New ADODB.Connection
Dim RS As ADODB.Recordset
Dim DataFile As Integer, Fl As Long, Chunks As Integer
Dim Fragment As Integer, Chunk() As Byte, i As Integer, FileName As String

Private Const ChunkSize As Integer = 16384
Private Const conChunkSize = 100

Private Sub cmdSave_Click()
    CN.Open "Provider=SQLOLEDB.1;Persist Security Info=False;User ID=sa;Initial Catalog=Pubs;Data Source=Test"
    Dim strSQL As String

    strSQL = "SELECT * FROM pub_info where pub_id = '9999'"
    RS.Open strSQL, CN, adOpenForwardOnly, adLockOptimistic

    RS.AddNew
      SavePicture
    RS.Update

    Set RS = Nothing
    Set RS = New Recordset
End Sub

Private Sub SavePicture()
    Dim strFileNm As String
    DataFile = 1
    Open strFileNm For Binary Access Read As DataFile
        Fl = LOF(DataFile)   ' Length of data in file
        If Fl = 0 Then Close DataFile: Exit Sub
        Chunks = Fl \ ChunkSize
        Fragment = Fl Mod ChunkSize
        ReDim Chunk(Fragment)
        Get DataFile, , Chunk()
        RS!logo.AppendChunk Chunk()
        ReDim Chunk(ChunkSize)
        For i = 1 To Chunks
            Get DataFile, , Chunk()
            RS!logo.AppendChunk Chunk()
        Next i
    Close DataFile
End Sub

OOPs My tiny edit caused a repeat posting

Here is an example saving image INTO an Access DB -
http://www.vb-helper.com/howto_store_image_in_access_db.html
If this is for a set exercise, and you have to store the image WITHIN the db, then I believe it will meet your need.
However, later, if you are developing real world applications, I would recommend my original suggestion.
HTH,
Rob

try it with search option.

Are you using this Project from within the Access database file? Or are you tring to access the file as a stand alone utility?

All the links provided by everyone give vaild answers, I suggest you read and implement the suggestions then come back and tell us how it worked out.

RobCr gives the best link.

thanx a looooooot robocr....ur help was really great,,i've been searching only for this,,,thanx a loot,,,thank you very much

thanx a looooooot robocr....ur help was really great,,i've been searching only for this,,,thanx a loot,,,thank you very much

Your welcome, glad I could help.
It is good (and rare) to get positive feedback.
Regards,
Rob

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.