Use the Same Code on Multiple Reports (1 Viewer)

Damo1412

Registered User.
Local time
Today, 05:30
Joined
Nov 15, 2010
Messages
65
Hi,

I have a database with a large number of reports based on a template.

Thanks to help previously provided by this forum (https://access-programmers.co.uk/forums/showthread.php?t=288559
) I have managed to link all of the images in the template so I can dynamically change or update them as required.

I have finally got round to rolling this out to all of the other reports based on this template however I have carried out further modifications resulting in quite a large amount of code for each report:
Code:
If Forms![formlocationcode]![live] = "Live" Then
Me.Header.Picture = DLookup("ImageLocation", "Images", "ImageName='A4 Header'")
Me.Accreditations.Picture = DLookup("ImageLocation", "Images", "ImageName='Accreditations'")
Me.CompanyAddressLine1.Visible = True
Me.CompanyAddressLine2.Visible = True
Me.CompanyAddressLine3.Visible = True
Me.CompanyPostCode.Visible = True
Me.CompanyTelephone.Visible = True
Me.CompanyEmail.Visible = True
Me.CompanyWebsite.Visible = True
Me.CompanyRegistration.Visible = True
Me.TestBox.Visible = False

Else
Me.CompanyAddressLine1.Visible = False
Me.CompanyAddressLine2.Visible = False
Me.CompanyAddressLine3.Visible = False
Me.CompanyPostCode.Visible = False
Me.CompanyTelephone.Visible = False
Me.CompanyEmail.Visible = False
Me.CompanyWebsite.Visible = False
Me.CompanyRegistration.Visible = False
Me.TestBox.Visible = True

End If
Instead of entering this code long hand into each report, I thought that it would be easier to place it in a module then simply call that module for each report. The only problem is I do not know enough about VBA (or any) coding to make this work.

Can anyone point me at a beginners guide which would show me how to do this?

Thanks in advance
 

Gasman

Enthusiastic Amateur
Local time
Today, 13:30
Joined
Sep 21, 2011
Messages
14,238
You could pass the report object to your module.
I'd probably pass the setting as well.?

Not tested
Code:
Call SetLiveData (Me,True)

Code:
Sub SetLiveData (rpt as Report, Setting as Boolean)
 

Uncle Gizmo

Nifty Access Guy
Staff member
Local time
Today, 13:30
Joined
Jul 9, 2003
Messages
16,274
Another method you might like to consider is having a single report and supplying its data from a table:-

http://www.niftyaccess.com/generate-multiple-reports/

Thereby creating different reports with different images from the information provided by the table.

Sent from my SM-G925F using Tapatalk
 

Users who are viewing this thread

Top Bottom