[AccessD] Replacing Graphics in Forms and Reports

Hewson, Jim JHewson at nciinc.com
Thu Aug 27 08:19:13 CDT 2009


Max,
I'm a little confused as to why you would go to all this trouble?

What I do is design forms and reports with specific graphic dimensions. 
I store the images I need in an external path one level below the FE.
When the form/report is opened the code pulls in the image to display. I
can change the image at anytime... I just need to keep the name of the
image the same.  The graphic or picture does not have to be a specific
size either, the image object needs to be set to zoom and it will fit
within the confines object's dimensions.

I use a similar method to display pictures of personnel on forms and
reports.  On the form I have a text box that holds the name of the
picture (including the extension).  The picture is placed in the
directory and on after update the form refreshes and the picture
displays.  I have almost 500 personnel in the database and some have two
pictures.  I use a toggle button to display either picture. 

One line of code should suffice:

"\images\" is the subdirectory to the FE.
GraphicFile is the name with extension of the picture or graphic

ImageObjectName.Picture = Application.CurrentProject.Path &
"\images\GraphicFile.gif" 

This works in A2K, A2003 and A2007

HTH

Jim

-----Original Message-----
From: accessd-bounces at databaseadvisors.com
[mailto:accessd-bounces at databaseadvisors.com] On Behalf Of Max Wanadoo
Sent: Thursday, August 27, 2009 5:57 AM
To: Access Developers discussion and problem solving
Subject: [AccessD] Replacing Graphics in Forms and Reports

Function fReplaceGraphics()
' I needed to change the graphics which over time became disjointed
and as the FE's location changed the
' graphics became incorrect.
' This function runs through all the Forms/Reports using the
AllForms/AllReports collection
' but as this is read-only we still need
' to open the report in design mode to make the changes
' Flipping the commented lines you can switch between Forms and Reports
' No error handling
' max.wanadoo at gmail.com
' Aug 09

 Dim obj As Object, rpt As Report, frm As Form, prp As Property, ctl As
Control
 Dim strObjName As String, strType As String
 strType = "AllForms"
 'For Each obj In CurrentProject.AllReports
 For Each obj In CurrentProject.AllForms
 strObjName = obj.Name

 ' We need to open it the object in Design view to make changes
 'DoCmd.OpenReport strObjName, acViewDesign
 DoCmd.OpenForm strObjName, acDesign

 ' We need to set the object type so that properties will point to the
right places.
 'Set rpt = Reports(strObjName)
 Set frm = Forms(strObjName)

 ' check the form/report properties for a picture
 'For Each prp In rpt.Properties
 For Each prp In frm.Properties
 If prp.Name = "Picture" Then
 If prp.Value <> "(none)" Then
 Debug.Print "FRM/RPT:"; strObjName, prp.Name, prp.Value
 ' put code in similar to below to make changes here.
 End If
 End If
 Next prp

 ' check the controls for a picture
 'For Each ctl In rpt.Controls
 For Each ctl In frm.Controls
 For Each prp In ctl.Properties
 If prp.Name = "Picture" Then
 If InStr(prp.Value, ".BMP") > 0 Then
 Select Case prp.Value
 Case "C:\My Documents\My Pictures\MGA\MGA.bmp"
 prp = "Z:\MCMFrontEnd.bmp"
 Case "C:\My Documents\My Pictures\MGA.bmp"
 prp = "Z:\MCMFrontEnd.bmp"
 Case "C:\_MCM\Photos\Thumbnails\MGA.BMP"
 prp = "Z:\MCMFrontEnd.bmp"
 Case "C:\_MCM\MCMFrontEnd.bmp"
 prp = "Z:\MCMFrontEnd.bmp"
 Case "C:\_MCM\Graphics\MGA-25.bmp"
 prp = "Z:\MCMFrontEnd.bmp"
 Case "C:\My Documents\My Pictures\MGA\MGA.bmp"
 prp = "Z:\MCMFrontEnd.bmp"
 Case "C:\Documents and Settings\Max\My Documents\My Pictures\ANSig.bmp"
 prp = "Z:\MCMFrontEnd.bmp"
 Case "C:\Documents and Settings\Max\My Documents\My
Pictures\Signatures\9659Sig.bmp"
 prp = "Z:\MCMFrontEnd.bmp"
 Case "C:\Documents and Settings\Manager's PC\My
Documents\_Pictures\MGA\MGA-25-150pix.bmp"
 prp = "Z:\MCMFrontEnd.bmp"
 Case "D:\Documents and Settings\Max Sherman\My Documents\My
Pictures\ansignature.bmp"
 prp = "Z:\MCMFrontEnd.bmp"
 Case "\\Server\svr-c\_MCM\Photos\Thumbnails\mga.bmp"
 prp = "Z:\MCMFrontEnd.bmp"
 Case "C:\_MCM\Graphics\MCM_Small.bmp"
 prp = "Z:\MCMFrontEnd.bmp"
 Case "C:\_MCM\References.bmp"
 prp = "Z:\References.bmp"
 Case "C:\My Documents\Database Local\StopHand.bmp"
 prp = "Z:\StopHand.bmp"
 Case "C:\My Documents\stop.bmp"
 prp = "Z:\StopHand.bmp"
 Case "C:\EATBloat\EatBloatRefs.bmp"
 prp = "Z:\References.bmp"
 Case "Z:\MCMFrontEnd.bmp", "Z:\References.bmp", "Z:\StopHand.bmp"
 ' no action - these are correct
 Case Else
 Debug.Print "CTL:", strObjName, ctl.Name, prp.Name, prp.Value
 End Select
 End If
 End If
 Next prp
 Next ctl
 'DoCmd.Close acReport, obj.Name, acSaveYes
 DoCmd.Close acForm, obj.Name, acSaveYes
 Next obj
End Function
-- 
AccessD mailing list
AccessD at databaseadvisors.com
http://databaseadvisors.com/mailman/listinfo/accessd
Website: http://www.databaseadvisors.com
################################################################################
If you have received this message in error, please contact the sender
immediately and be aware that the use, copying, or dissemination of 
this information is prohibited. This email transmission contains 
information from NCI Information Systems, Inc. that may be considered 
privileged or confidential and is intended solely for the named 
recipient.
################################################################################




More information about the AccessD mailing list