replace embedded logo images

supmktg

Registered User.
Local time
Today, 07:12
Joined
Mar 25, 2002
Messages
360
I need to replace the embedded image on a large number of reports and forms. I'm looking for a way to loop through all of the controls in my forms and reports and if the control is an image, replace the embedded image with a new one. Can this be done using vba?

Thanks,
Sup
 
Yeah, check out the AllForms and AllReports collections, which contain AccessObject objects, which you can use to find the names of the forms/reports you are talking about.

Alternatively you can use the hidden system table MSysObjects to find an authoritative list of the objects in your database. In that case you would open a recordset as a control structure for a loop that will yield the names of the objects.

Once you have the name you can programmatically open a form/report in design view, and enumerate its controls collection . . .
Code:
   dim frm as access.form
   dim ctrl as access.control
   DoCmd.OpenForm "FormName", acDesign, , , , acHidden
   set frm = Forms("FormName")
   for each ctrl in frm.controls
      if ctrl.controltype = acImage then
         debug.print frm.name, ctrl.name, ctrl.left, ctrl.top
      end if
   next
This code enumerates the controls on the form, and prints for the form.name, control.name and location.

hth
 
Hi Lagbolt,

I have actually found some sample code from Allen Brown that will loop through and open each form in design view, and then loop thru the controls.

What I can't figure out is if I can change the embedded image file programatically.

I'd like to do something like this:

Code:
If ctl.ControlType = (acImage?) Then
'change image source
ctl.(picture?) = newLogo.bmp
end if

Any ideas?

Thanks,
Sup
 
Try first, ask questions later!

Yeah, do that. What happens? Does it work?
Code:
If ctl.ControlType = acImage Then
   [COLOR="Green"]'change image source[/COLOR]
   ctl.picture = "C:\Pictures\newLogo.bmp"
end if
:)
 
The acImage and .picture references were guesses that happened to be correct. I guess I should have relied on intellisense to confrim that.
The hardest part for me was setting the sizemode correctly, as it changed when importing the new image. I did get it to work with the following code:

Code:
Function ReplaceImage(strReportName As String, _
        Optional bSaveAndClose As Boolean, Optional bHidden As Boolean)
    'Purpose:   Replace Logo Image on Reports
    
    Dim rpt As Report 'Form
    Dim ctl As Control
    Dim bChanged As Boolean
        
    'Open the form in design view
    DoCmd.OpenReport strReportName, acDesign, acHidden, acWindowNormal
    Set rpt = Reports(strReportName)
    
    'Find the images that are old logo
    For Each ctl In rpt.Controls
        If ctl.ControlType = acImage Then
            If ctl.Picture = "C:\Pics\Logo1.bmp" Then
 
                  ctl.Picture = "C:\Pics\Logo2.jpg"
                  ctl.SizeMode = 1 '=stretch/shrink to fit
                  bChanged = True

            End If
        End If
    Next
    
    
    

    Set ctl = Nothing
    Set rpt = Nothing
    If Not bChanged Then
        DoCmd.Close acReport, strReportName, acSaveNo
    ElseIf bSaveAndClose Then
        DoCmd.Close acReport, strReportName, acSaveYes
    End If
    
End Function

Thanks,
Sup
 

Users who are viewing this thread

Back
Top Bottom