Available in the LEADTOOLS Imaging toolkit. |
Including Images in a Report (Access 95 and 97)
Take the following steps to create a report that includes images from an ODBC data source. (You can use a similar strategy to include images where only the pathname is stored in the database.)
Note: Quality of the output depends on the video mode. For best results, use high color or true color.
1. Start with the project that you created in Using ODBC to Access Image Data.
2. In the Database window, select the Reports tab, and click the New button.
3. In the New Report window, select Design View, specify Query1 as the data source, and click OK.
4. On the Insert pull-down menu, use the Custom Control option to select the Lead Control.
5. Click the OK button. The lead control appears on the report.
6. Size and position the control as you want it to appear on your report.
7. In the Properties box for the LEAD control, make the following changes:
a. Set the Border Style property to solid.
b. Set the Name property to LeadOnRpt.
8. Add a TextBox control to your report and change its properties as follows:
a. Set the Control Source property to who.
b. Set the Name property to Cwho.
9. Add the following code to the Detail object's Print event:
On Error GoTo ERRORHANDLER
' Declare a local variables
Dim ODBCString, SQLString
Static GetNextRecord As Boolean
If GetNextRecord Then
LeadOnRpt.dbMoveNext
Else
' Initialize the Lead control.
LeadOnRpt.AutoRepaint = True
LeadOnRpt.PaintDither = PAINTDITHER_DIFFUSION
LeadOnRpt.PaintPalette = PAINTPALETTE_FIXED
LeadOnRpt.AutoRepaint = True
LeadOnRpt.AutoSetRects = True
LeadOnRpt.PaintSizeMode = PAINTSIZEMODE_FIT
' Open the ODBC database.
' Use the same SELECT statement that is used for the data control.
' Note that the image field must be listed first in the SELECT statement.
ODBCString = "ODBC;DSN=LEADAC32"
SQLString = "SELECT photo FROM people ORDER BY who"
LeadOnRpt.dbOpen ODBCString, SQLString, "photo", DB_OPENOPTIONS_READONLY
' Set the LEAD control's database properties
LeadOnRpt.dbLoadBits = 0
LeadOnRpt.dbLockingMode = DB_LOCKINGMODE_OPTIMISTIC
GetNextRecord = True
End If
Exit Sub
ERRORHANDLER:
MsgBox Err.Source + " " + CStr(Err.Number) + Chr(13) + Err.Description
10. Add the following code to the Report object's Close event:
LeadOnRpt.dbClose
11. For printing the report, add a command button to your main form. Using the Command Button Wizard, you can select Report Operations and Print Report.
12. Run your program to test it.