[AccessD] Replacing Graphics in Forms and Reports

Max Wanadoo max.wanadoo at gmail.com
Thu Aug 27 05:56:58 CDT 2009


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



More information about the AccessD mailing list