Writing and Reading Multipage Files (Access 2.0)

Take the following steps to create a multipage file, then load and display the images from the file. Only TIFF (MPT) and PCX (DCX) formats support multipage files.

1. Start Microsoft Access 2.0.

2. On the File pull-down menu, use the New Database option to create a new database.

3. image\btnmodul.gif In the Database window, select the Module tab, and click the New button.

4. On the File pull-down menu, use the Load Text option to load the L_ACCESS.BAS file from the INCLUDE directory. (Use the Merge option when loading the file.)

5, Close the file, and save it as the Global Constants module.

6. image\btnform.gif In the Database window, select the Form tab, and click the New button.

7. In the New Form window, click the Blank Form Button.

8. Click and drag the form's detail area to make it 5 1/2 inches deep (large enough to fill the screen when you maximize it.)

9. Add two Lead controls to the form. To add each control, on the Edit pull-down menu, use the Insert Object option to select the Lead Control, then click the OK button.

10. In the properties box, change the name of the first control to LEAD1, and the second one to LEAD2.

11. In the property box for the form, select the On Activate event, select the code builder, and add the following code. In online help, you can use the Edit pull-down menu to copy the block of code.

This code loads two bitmaps, saves them both into a single multipage TIFF file, loads them again from the TIFF file, and displays them side-by-side.

Sub Form_Activate ()
  DoCmd Maximize
  Me.ScrollBars = None
  Me.Painting = True

  'Disable automatic repainting of the image.
  Me![LEAD1].Object.AutoRepaint = False
  Me![LEAD2].Object.AutoRepaint = False

  'Turn off scroll bars to make sure we use the full client area.
  Me![LEAD1].Object.AutoScroll = False
  Me![LEAD2].Object.AutoScroll = False

  'Hide the controls until we are ready to look at them.
  Me![LEAD1].Visible = False
  Me![LEAD2].Visible = False

  'Display the form and set the mouse pointer to an hourglass.
  DoCmd Hourglass True

  'Load the bitmaps. These hard-coded path names may be different on your system.
  Me![LEAD1].Object.Load "c:\lead\images\image1.cmp", 0, 0, 1
  Me![LEAD2].Object.Load "c:\lead\images\image2.cmp", 0, 0, 1

  'Save the bitmaps to a single multipage TIFF file
  Me![LEAD1].Object.Save "c:\lead\images\combined.mpt", FILE_TIF, 24, 0, SAVE_OVERWRITE
  Me![LEAD2].Object.Save "c:\lead\images\combined.mpt", FILE_TIF, 24, 0, SAVE_APPEND

  'Get information about the images so that we can size the controls.
  Me![LEAD1].Object.GetFileInfo "c:\lead\images\combined.mpt", 1, 0
  Me![LEAD2].Object.GetFileInfo "c:\lead\images\combined.mpt", 2, 0

  'Clear the bitmaps from memory
  Me![LEAD1].Object.Bitmap = 0
  Me![LEAD2].Object.Bitmap = 0

  'Make the controls visible so that we can size and position them.
  'They will not really appear until we load an image and paint it.
  Me![LEAD1].Visible = True
  Me![LEAD2].Visible = True

  'Set the variables used for preserving the aspect ratio.
  HeightFactor1 = Me![LEAD1].Object.InfoHeight
  WidthFactor1 = Me![LEAD1].Object.InfoWidth
  HeightFactor2 = Me![LEAD2].Object.InfoHeight
  WidthFactor2 = Me![LEAD2].Object.InfoWidth
  HeightAllowed = Me.WindowHeight * .8
  WidthAllowed = Me.WindowWidth * .45

  'Center each LEAD control on half of the form, preserving the aspect ratio.
  'Check to see if using the maximum width will make the image too tall.
  'Set the dimensions based on the result.
  If (WidthAllowed * HeightFactor1) / WidthFactor1 < HeightAllowed Then
    Me![LEAD1].Left =  (Me.WindowWidth / 4) - (WidthAllowed / 2)
    Me![LEAD1].Width = WidthAllowed
    Me![LEAD1].Height = (Me![LEAD1].Width * HeightFactor1) / WidthFactor1
    Me![LEAD1].TOP = (Me.WindowHeight - Me![LEAD1].Height) / 2
  Else
    Me![LEAD1].TOP = (Me.WindowHeight - HeightAllowed) / 2
    Me![LEAD1].Height = HeightAllowed
    Me![LEAD1].Width = (Me![LEAD1].Height * WidthFactor1) / HeightFactor1
    Me![LEAD1].Left = (Me.WindowWidth / 4) - (Me![LEAD1].Width / 2)
  End If

  If (WidthAllowed * HeightFactor2) / WidthFactor2 < HeightAllowed Then
    Me![LEAD2].Left = (Me.WindowWidth * 3/4) - (WidthAllowed / 2)
    Me![LEAD2].Width = WidthAllowed
    Me![LEAD2].Height = (Me![LEAD2].Width * HeightFactor2) / WidthFactor2
    Me![LEAD2].TOP = (Me.WindowHeight - Me![LEAD2].Height) / 2
  Else
    Me![LEAD2].TOP = (Me.WindowHeight - HeightAllowed) / 2
    Me![LEAD2].Height = HeightAllowed
    Me![LEAD2].Width = (Me![LEAD2].Height * WidthFactor2) / HeightFactor2
    Me![LEAD2].Left = (Me.WindowWidth * 3/4) - (Me![LEAD2].Width / 2)
  End If

  'Load the bitmaps from the multipage TIFF file
  Me![LEAD1].Object.Load "c:\lead\images\combined.mpt", 24, 1, 1
  Me![LEAD2].Object.Load "c:\lead\images\combined.mpt", 24, 2, 1

  'Set the image display sizes to match the LEAD controls
  ImageHeight1 = Me![LEAD1].Object.ScaleHeight 
  ImageWidth1 = Me![LEAD1].Object.ScaleWidth
  Me![LEAD1].Object.SetDstRect 0, 0, ImageWidth1, ImageHeight1
  Me![LEAD1].Object.SetDstClipRect 0, 0, ImageWidth1, ImageHeight1

  ImageHeight2 = Me![LEAD2].Object.ScaleHeight 
  ImageWidth2 = Me![LEAD2].Object.ScaleWidth
  Me![LEAD2].Object.SetDstRect ImageLeft2, ImageTop2, ImageWidth2, ImageHeight2
  Me![LEAD2].Object.SetDstClipRect ImageLeft2, ImageTop2, ImageWidth2, ImageHeight2

  'Display the images
  Me![LEAD1].Object.ForceRepaint
  Me![LEAD2].Object.ForceRepaint

  'Set the mouse pointer back to the default
  DoCmd Hourglass False

End Sub

12. Run your program to test it.

Note: For 256-color mode, you can improve the image quality as explained in Palette Usage in Microsoft Access.