DBPix Sample Source Code: Embedded_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 tEmbedded"
.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()
' 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
' Load the image data into each of the DBPix controls
If (Not rst.EOF) Then
ActiveXCtl0.ImageViewBlob (rst("ImgThumbnail"))
Id0 = rst("ItemId")
rst.MoveNext
End If
If (Not rst.EOF) Then
ActiveXCtl1.ImageViewBlob (rst("ImgThumbnail"))
Id1 = rst("ItemId")
rst.MoveNext
End If
If (Not rst.EOF) Then
ActiveXCtl2.ImageViewBlob (rst("ImgThumbnail"))
Id2 = rst("ItemId")
rst.MoveNext
End If
If (Not rst.EOF) Then
ActiveXCtl3.ImageViewBlob (rst("ImgThumbnail"))
Id3 = rst("ItemId")
rst.MoveNext
End If
If (Not rst.EOF) Then
ActiveXCtl4.ImageViewBlob (rst("ImgThumbnail"))
Id4 = rst("ItemId")
rst.MoveNext
End If
If (Not rst.EOF) Then
ActiveXCtl5.ImageViewBlob (rst("ImgThumbnail"))
Id5 = rst("ItemId")
rst.MoveNext
End If
If (Not rst.EOF) Then
ActiveXCtl6.ImageViewBlob (rst("ImgThumbnail"))
Id6 = rst("ItemId")
rst.MoveNext
End If
If (Not rst.EOF) Then
ActiveXCtl7.ImageViewBlob (rst("ImgThumbnail"))
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 "Embedded_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
|