I using following codes to add images in my project & its working properly in winxp but not working properly in win7 platform. please help me to find the problem. If you any other better codes to add images to MS-Access databae then please suggest. thanks

Public Sub FillFields()
    If Not (adorsstudent.BOF And adorsstudent.EOF) Then
        Set Image1.DataSource = adorsstudent 
        Image1.DataField = "Picture" 
    End If
End Sub


Private Sub cmdAddImage_Click()
       Dim bytData() As Byte
    'Dim strDescription As String
    On Error GoTo err
    With dlImage 'common dialog box.
          'filtering so only jpg's and gifs are shown!
        .Filter = "Picture Files (*.jpg, *.gif)|*.jpg;*.gif"
        .DialogTitle = "Select Picture"  'sets the title of it.
        .ShowOpen  'show the open dialog box.
          'bit to "convert" the image to binary.
        Open .FileName For Binary As #1
        ReDim bytData(FileLen(.FileName))
    End With
    Get #1, , bytData
    Close #1
    With adorsstudent
         .Fields("Picture").AppendChunk bytData  'adding the picture to the db
    End With
    FillFields
    Exit Sub
err:
    If err.Number = 32755 Then     'simple error check.
   Else
        MsgBox err.Description
        err.Clear
    End If

End Sub

Dani AI

Generated

This problem is usually environmental rather than algorithmic: code that happily wrote/displayed images on XP can fail on Windows 7 because of UAC, OCX/Runtime registration, 32-bit vs 64-bit registration, or differences in how Access/Jet/ACE handles OLE blobs. The likely culprits to check first are permissions (is the MDB writable where the app is installed?), missing or unregistered VB6 controls (CommonDialog/MSCOMCTL), and whether the Access database engine on the Win7 machine matches the developer machine.

Quick checklist to diagnose and fix:

  • Run the program elevated (right‑click → Run as administrator) to see if it is a permissions problem. If that fixes it, move the database to a per‑user or shared data folder (%APPDATA% or Public Documents) and avoid writing into Program Files.
  • Verify the VB6 runtime and any OCXs your project uses are present and registered on the Win7 machine. On 64‑bit Windows register 32‑bit OCXs from SysWOW64 using the 32‑bit regsvr32.
  • Confirm the Access/Jet/ACE engine is installed and the correct driver (Jet 4.0 vs ACE) is being used — mismatched engines can change behavior for OLE fields.
  • Test the binary read path separately (save the selected file to Temp from the app) to ensure the file is read correctly before writing to the DB.
  • Prefer ADODB.Stream or parameterized ADO parameters for robust binary I/O on newer Windows; they avoid text/encoding pitfalls that can show up across OS versions.
  • If the field is an Access OLE Object, be aware Access often wraps the image with an OLE header and display behavior differs by Access/Windows version. For long‑term reliability, consider storing files on disk and keeping paths in the DB, or use Access Attachment fields (ACCDB).

Notes on the answers already posted: ’s approach is on the right track, but make sure the recordset variable you open is the one you append to (open the correct rs, use AddNew/Edit before AppendChunk, then Update). ’s deployment pointers are relevant — the issue is often missing runtime/OCX registration on Win7 rather than the AppendChunk logic itself.

Recommended Answers

All 2 Replies

Most of your code is clashing with win 7. Have a look at my tutorial here.

Then have a look at one of my old posts... here.

This is my code in adding picture to database:

Add this code to your module:

Public Function SavePictureToDB(tblName As String, _
                                WHERECondition As String, _
                                FldName As String, _
                                strFileNm As String, _
                                xcn As ADODB.Connection) As Boolean

   Dim FF         As Integer
   Dim rs_pic     As ADODB.Recordset

   Dim Fl         As Long
   Dim DataFile   As Long
   Dim Chunks     As Integer
   Dim ChunkSize  As Integer
   Dim Fragment   As Integer
   Dim Chunk()    As Byte

   ChunkSize = 16384

   FF = FreeFile()
   DataFile = FileLen(strFileNm)
   ReDim Chunk(DataFile)
   Open strFileNm For Binary Access Read As #FF
      Get #FF, , Chunk
      tmp_rc.Open "SELECT * FROM " & tblName & " " & WHERECondition, xcn
      rs_pic(FldName).AppendChunk (Chunk())
      rs_pic.Update
      rs_pic.Close
   Close #FF
   Set rs_pic = Nothing
   SavePictureToDB = True

End Function

To use it:

Call SavePictureToDB("Guardians", "WHERE ID = 1", "Picture", PicURL, cn)

"Guardians" is the Table name
"WHERE ID = 1" is the condition,
"Picture" is the OLE Object / Picture field in your database table
PicURL is the filename of the image you want to save in the database.
cn is your connection object (ADODB.CONNECTION)

Just play with the code above and customize it according in your needs,

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.