saving and retrieving pictures using vb6 and ms access

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Hiram13
    New Member
    • Jun 2013
    • 6

    #1

    saving and retrieving pictures using vb6 and ms access

    Hi
    Am developing a school software and i have a form named Admission which i want to include the pictures of students, i have managed to upload the picture using this code:
    Code:
    Private Sub Command1_Click()
     Dim pic As StdPicture
    dlgPicture.Filter = "Pictures (*.bmp;*.jpg)|*.bmp;*jpg|"
    dlgPicture.ShowOpen
    filen = dlgPicture.FileName
    Picture1.Picture = LoadPicture(filen)
    End Sub
    The problem now is how to save and retrieve those pictures. Am using VB6.0 connecting to MS Access database using module and i want pictures to be saved in table admission field called images
    Can someone please help!
    Last edited by Rabbit; Jun 20 '13, 03:18 PM. Reason: Please use code tags when posting code.
  • Mihail
    Contributor
    • Apr 2011
    • 759

    #2
    As far as I know (maybe I am wrong), a picture can't be stored in Access database. But the picture path can.

    Assuming that you already have a form bounded to table Admission, create a new field (Student_Pic) in this table and store here the path(s) to every student picture.

    Then manage that your Picture control to be updated using the properly path (the path stored in the new created field).

    Hope this is a help for you.

    Comment

    • Killer42
      Recognized Expert Expert
      • Oct 2006
      • 8429

      #3
      Actually, this topic has been covered here more than once. Try the search box.

      I did a quick search for the terms "vb access save image" and found a couple of likely-sounding entries...

      Comment

      • Hiram13
        New Member
        • Jun 2013
        • 6

        #4
        thanks guys i was able to save and retrieve pictures using this code:
        Code:
        Dim arrImageByte() As Byte
            Dim fNum As Integer
            
            Dim rs As New ADODB.Recordset
            Dim strPhotoPath As String
            Dim isImage As Boolean
            If Me.imgPhoto.Picture <> LoadPicture("") Then
                SavePicture Me.imgPhoto.Picture, App.Path & "\tmpphoto.jpg"
                strPhotoPath = App.Path & "\tmpphoto.jpg"
                
                ReDim arrImageByte(FileLen(strPhotoPath))
                fNum = FreeFile()
                Open strPhotoPath For Binary As #fNum
                Get #fNum, , arrImageByte
                Close fNum
                
                isImage = True
            End If
            
            rs.Open "student", conn, adOpenStatic, adLockOptimistic, adCmdTable
            
            With rs
                .AddNew
                .Fields("Name") = Me.txtName.Text
                
                If isImage = True Then _
                    .Fields("photo").AppendChunk arrImageByte
                .Update
            
            End With
            
            rs.Close
            Set rs = Nothing
        Last edited by Frinavale; Jul 15 '13, 01:55 PM. Reason: Added code tags. Please post code in code tags in the future.

        Comment

        • Killer42
          Recognized Expert Expert
          • Oct 2006
          • 8429

          #5
          Glad to see you found a solution, and thanks for sharing it. This will be helpful for others who come searching with similar questions.

          I think it'd be fair to say that pretty much anything you can get into your computer can be stored in your database, somehow.

          As Mihail said, you could store the images elsewhere and just include some sort of link in the database. I personally find it more convenient to keep everything together in the database. Each approach has its good and bad points.

          Don't forget to take into consideration what this image will do to your record size. If you do come across any database issues, keep in mind our Access Forum.

          Comment

          Working...