Add a logo to the report header with code

A

alexrs2k

I'm trying to put a logo fo the company in report header which is created
with code, but when it gets to the Set imgLogo, it triggers an error "The
section number is invalid". Whenever I use the instruction
rpt.Section(acHeader).Height = 300, triggers the same error.
The section number for the report Header is acHeader . Any idea how to refer
to the report header section programmatically. Thank you.

'Create the report
Set rpt = CreateReport
' set properties of the Report
With rpt
.Width = 8500
.Section(acDetail).Height = 300
.RecordSource = strSQL
End With
' Open SQL query as a recordset
Set db = CurrentDb
Set rs = db.OpenRecordset(strSQL)

' Create Logo
Set imgLogo = CreateReportControl(rpt.Name, acImage, acHeader, , , 0, 0)
imgLogo.Picture = Application.CurrentProject.Path & "\Images\Logo.JPG"
imgLogo.SizeToFit
 
M

Marshall Barton

alexrs2k said:
I'm trying to put a logo fo the company in report header which is created
with code, but when it gets to the Set imgLogo, it triggers an error "The
section number is invalid". Whenever I use the instruction
rpt.Section(acHeader).Height = 300, triggers the same error.
The section number for the report Header is acHeader . Any idea how to refer
to the report header section programmatically. Thank you.

'Create the report
Set rpt = CreateReport
' set properties of the Report
With rpt
.Width = 8500
.Section(acDetail).Height = 300
.RecordSource = strSQL
End With
' Open SQL query as a recordset
Set db = CurrentDb
Set rs = db.OpenRecordset(strSQL)

' Create Logo
Set imgLogo = CreateReportControl(rpt.Name, acImage, acHeader, , , 0, 0)
imgLogo.Picture = Application.CurrentProject.Path & "\Images\Logo.JPG"
imgLogo.SizeToFit


When you use CreateReport, it has the page header, page
footer and detail sections. To toggle the existence of the
report header and footer sections use:
DoCmd.RunCommand acCmdReportHdrFtr

Similarly, for the page header and footer sections:
DoCmd.RunCommand acCmdPageHdrFtr
 
A

alexrs2k

Hi. Barton, you are the man. I ran up and down on google for hours to get a
solution, and I didn't find any. Thank you!!!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top