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: External_Multi
Back to sample
Option Compare Database
Option Explicit

Dim cn As ADODB.Connection
Dim rst As ADODB.Recordset

Dim CurrentPage

' Id's for each record, used to open 'Detail' form at a specific record
Dim Id0
Dim Id1
Dim Id2
Dim Id3
Dim Id4
Dim Id5
Dim Id6
Dim Id7
Dim Id8


Private Sub Form_Load()

    ' Open the recordset and update the controls
    CurrentPage = 1

    Set cn = CurrentProject.Connection
    Set rst = New ADODB.Recordset

    With rst
        .PageSize = 8
        .ActiveConnection = cn
        .Source = "SELECT * FROM tExternal"
        .LockType = adLockOptimistic
        .CursorType = adOpenStatic
        .Open
    End With

    UpdateControls
End Sub

Private Sub NextBtn_Click()
    CurrentPage = CurrentPage + 1
    UpdateControls
End Sub

Private Sub PrevBtn_Click()
    CurrentPage = CurrentPage - 1
    UpdateControls
End Sub


Private Sub UpdateControls()
    Dim Folder As String
    Dim FullPath As String
    
    Folder = GetImgFolder
    
    ' Clear all the DBPix controls
    ActiveXCtl0.ImageViewBlob (Null)
    ActiveXCtl1.ImageViewBlob (Null)
    ActiveXCtl2.ImageViewBlob (Null)
    ActiveXCtl3.ImageViewBlob (Null)
    ActiveXCtl4.ImageViewBlob (Null)
    ActiveXCtl5.ImageViewBlob (Null)
    ActiveXCtl6.ImageViewBlob (Null)
    ActiveXCtl7.ImageViewBlob (Null)
    
    ' Reset the record ID's
    Id0 = -1
    Id1 = -1
    Id2 = -1
    Id3 = -1
    Id4 = -1
    Id5 = -1
    Id6 = -1
    Id7 = -1
    
    ' Get the number of pages and records, and update the text and Prev/Next button states
    Dim NumPages
    Dim NumRecs
    NumPages = rst.PageCount
    NumRecs = rst.RecordCount
    
    PageLabel.Value = "Page " & CurrentPage & " of " & NumPages
    
    If CurrentPage > NumPages Then CurrentPage = NumPages
    If CurrentPage < 1 Then CurrentPage = 1
    
    ' Set the page we want to display
    rst.AbsolutePage = CurrentPage
    
    'Update Prev/Next buttons
    If CurrentPage = NumPages Then
        DoCmd.GoToControl "ActiveXCtl0"
        NextBtn.Enabled = False
    Else
        NextBtn.Enabled = True
    End If

    If CurrentPage = 1 Then
        DoCmd.GoToControl "ActiveXCtl0"
        PrevBtn.Enabled = False
    Else
        PrevBtn.Enabled = True
    End If
    
    ' Display the image files in each of the DBPix controls
    If (Not rst.EOF) Then
        FullPath = Folder & "t" & rst("ItemId") & ".jpg"
        If Dir(FullPath) <> vbNullString Then ActiveXCtl0.ImageViewFile FullPath
        Id0 = rst("ItemId")
        rst.MoveNext
    End If

    If (Not rst.EOF) Then
        FullPath = Folder & "t" & rst("ItemId") & ".jpg"
        If Dir(FullPath) <> vbNullString Then ActiveXCtl1.ImageViewFile FullPath
        Id1 = rst("ItemId")
        rst.MoveNext
    End If

    If (Not rst.EOF) Then
        FullPath = Folder & "t" & rst("ItemId") & ".jpg"
        If Dir(FullPath) <> vbNullString Then ActiveXCtl2.ImageViewFile FullPath
        Id2 = rst("ItemId")
        rst.MoveNext
    End If

    If (Not rst.EOF) Then
        FullPath = Folder & "t" & rst("ItemId") & ".jpg"
        If Dir(FullPath) <> vbNullString Then ActiveXCtl3.ImageViewFile FullPath
        Id3 = rst("ItemId")
        rst.MoveNext
    End If

    If (Not rst.EOF) Then
        FullPath = Folder & "t" & rst("ItemId") & ".jpg"
        If Dir(FullPath) <> vbNullString Then ActiveXCtl4.ImageViewFile FullPath
        Id4 = rst("ItemId")
        rst.MoveNext
    End If

    If (Not rst.EOF) Then
        FullPath = Folder & "t" & rst("ItemId") & ".jpg"
        If Dir(FullPath) <> vbNullString Then ActiveXCtl5.ImageViewFile FullPath
        Id5 = rst("ItemId")
        rst.MoveNext
    End If

    If (Not rst.EOF) Then
        FullPath = Folder & "t" & rst("ItemId") & ".jpg"
        If Dir(FullPath) <> vbNullString Then ActiveXCtl6.ImageViewFile FullPath
        Id6 = rst("ItemId")
        rst.MoveNext
    End If

    If (Not rst.EOF) Then
        FullPath = Folder & "t" & rst("ItemId") & ".jpg"
        If Dir(FullPath) <> vbNullString Then ActiveXCtl7.ImageViewFile FullPath
        Id7 = rst("ItemId")
        rst.MoveNext
    End If

End Sub


' Generic handler for clicks - opens the relevant 'Zoom' view
Private Sub HandleClick(Id As Long)
    If (Id > -1) Then
        Dim strWhereCategory
        strWhereCategory = "[ItemId ]=" & Id
        DoCmd.OpenForm "External_Zoom", acNormal, , strWhereCategory, , acDialog
    End If
End Sub


' Click event handlers for each control
' Open the 'Zoom' view showing the main image

Private Sub ActiveXCtl0_Click()
    HandleClick (Id0)
End Sub

Private Sub ActiveXCtl1_Click()
    HandleClick (Id1)
End Sub

Private Sub ActiveXCtl2_Click()
    HandleClick (Id2)
End Sub

Private Sub ActiveXCtl3_Click()
    HandleClick (Id3)
End Sub

Private Sub ActiveXCtl4_Click()
    HandleClick (Id4)
End Sub

Private Sub ActiveXCtl5_Click()
    HandleClick (Id5)
End Sub

Private Sub ActiveXCtl6_Click()
    HandleClick (Id6)
End Sub

Private Sub ActiveXCtl7_Click()
    HandleClick (Id7)
End Sub


Back to sample