Home
DBPix
Download
Order
Testimonials
Support
Tutorials
Samples
KnowledgeBase
Links
Revision History
Documentation
Search
Contact
Site Map

Graph: DBPix image storage vs OLE Embedding and Linking in Microsoft Access


DBPix Sample Source Code: fsubEditSubImage
Back to sample
Option Compare Database
Option Explicit

    ' When the user deletes a record we have to save the current Id in order to delete the image files
    ' after the delete is confirmed
    Dim DeleteImgId As Long
    
Private Sub Form_Current()
    
    Dim DetailImgPath As String
    
    DBPixSubThumb.ImageViewBlob (Null)
    
    If IsNull(Me!ImageId) Then
        DBPixSubMain.ImageViewBlob (Null)
    Else
        DetailImgPath = GetImgFolder & "\images\sub\" & Me!ImageId & ".jpg"

        If Dir(DetailImgPath) <> vbNullString Then
            DBPixSubMain.ImageViewFile DetailImgPath
        Else
            DBPixSubMain.ImageViewBlob (Null)
        End If
    End If
End Sub


Private Sub DBPixSubMain_ImageModified()

    Dim DetailImgPath As String
    Dim ThumbImgPath As String

    'In order to have access to the autonumber value (for the filename) we must have modified the record,
    ' so update the ImageModified field
    Me!ImageModified = Now()

    DetailImgPath = GetImgFolder & "\images\sub\" & Me!ImageId & ".jpg"
    ThumbImgPath = GetImgFolder & "\images\sub\" & Me!ImageId & "t.jpg"

    If DBPixSubMain.ImageBytes < 1 Then
        ' Image is empty/cleared/deleted
        
        ' Clear the thumbnail control
        DBPixSubThumb.ImageViewBlob (Null)
        
        ' Delete the detail and thumbnail image files if they exist
        If Dir(DetailImgPath) <> vbNullString Then Kill DetailImgPath
        If Dir(ThumbImgPath) <> vbNullString Then Kill ThumbImgPath
    Else
         ' Save the image
        If DBPixSubMain.ImageSaveFile(DetailImgPath) Then
            DBPixSubThumb.ImageLoadBlob (DBPixSubMain.Image)
            DBPixSubThumb.ImageSaveFile (ThumbImgPath)
        Else
            ' Error saving - main image - clear the thumbnail control
            DBPixSubThumb.ImageViewBlob (Null)
        End If
    End If
End Sub

Private Sub Form_Delete(Cancel As Integer)
' Record delete about to occur - save the Id so we can delete the files if the delete is confirmed
    If Not IsNull(Me!ImageId) Then
        DeleteImgId = Me!ImageId
    Else
        DeleteImgId = 0
    End If
End Sub


Private Sub Form_AfterDelConfirm(Status As Integer)
    If Status = acDeleteOK Then
        If DeleteImgId > 0 Then
            Dim DetailImgPath As String
            Dim ThumbImgPath As String

            DetailImgPath = GetImgFolder & "\images\sub\" & DeleteImgId & ".jpg"
            ThumbImgPath = GetImgFolder & "\images\sub\" & DeleteImgId & "t.jpg"
        
            ' Delete the detail and thumbnail image files if they exist
            If Dir(DetailImgPath) <> vbNullString Then Kill DetailImgPath
            If Dir(ThumbImgPath) <> vbNullString Then Kill ThumbImgPath
        End If
    End If
    
    DeleteImgId = 0
End Sub



Back to sample