HandsOn Writing the Detail Format Event Procedure

1. Use the rptCustomers report you created in Hands-On 25-1.

2. In the Visual Basic Editor Code window for the rptCustomers report, type the following Detail_Format event procedure. Do not type the Option Compare Database and Option Explicit statements if they are already at the top of the Code window.

Option Compare Database Option Explicit

Dim shaded As Boolean

Private Sub Detail_Format(Cancel As Integer, _ FormatCount As Integer) If shaded Then

Me.Detail.BackColor = vbYellow

Else

Me.Detail.BackColor = vbWhite End If shaded = Not shaded

End Sub

Notice that at the top of the module sheet (in the module's Declarations area) we have placed the following statement:

Dim shaded As Boolean

The above statement declares the global variable of the Boolean type to keep track of the alternate rows.

When you run the report, upon printing the Detail section, Access will check the value of the shaded variable. If the value is True, it will change the background of the formatted row to yellow (which produces a light

Event Programming in Forms and Reports gray background when printed on a laser printer). The shaded value will then be set to False for the next row by using the following statement:

shaded = Not shaded

The above statement works as a toggle. If shaded was True, it will be False now, and so on.

3. Run the rptCustomers report. When the input box appears prompting you for the criteria, type an asterisk (*) and press OK.

.4// Customers

ftjiww Cofi&A? C'MfiL

Ox,-

a i Pot.' Cafj

Fkau

To.1

ALF 10 .<Nt«dr FUkltibfc P.lala,-ole-i:

Gate* Ptpr«<rJ Obere Gt. ~>

12309

G« inaij'

0300074-

030007S

AHÄ1H .-Hrtlhll'j Bni'Sttd-a rnalhilo

Owner .-'.ilailflatonilkcl

F.V >1® DJ .

MOfil

Mi •(■:■:■

£3 555+7

©55537

ARID I .inlorloMocerp Ts*.* ■'nlcrle Morero

Owner r.ldalncc 2312

UfJto 01 .

05D23

r.l t

® 55539

APOUT .HolivJ 1* Hem Tlvjiiar H-afiJy

Caltf Rt pretend l-XH-srotr Ci].

WAI IDP

UK

£17 p S5-

(IT '(■ S5-

E B'GC frrghrrJr rnaU-kty CItI: Ina Btrghrd Onl«r ^ludri: lo E-cr/.r.'rvii^n $

lliti

Ow*J«n

0321-123

Gffil-123

BLAUB Ela-ti :j« Ddl.atr r Haiurva

catti Peprertrt Far tri t. 3

Marrlittn

63 306

Git manor

0621-08+.

0621-cea:

tLQNP Haiifi paefii: Freda nut cifc&i Mafttlni runs :(,i<izt utter

Cfrsr l-:'.i'j

670CD

Fraxe

8860.15.

$$£0.15.3

BO LID BolUoCotriUs pKfiorFAarlriCcfnrntr

Owner 0." .'raflil.&T

r.biiti

28023

C»dn

C905S2

{305S3

E.ij N -P Bon^p' Larina liblun

owner IZ.ru der Bouchtr r

MarrHle

13006

fma

312+.«.

912*.«.*

bottt.1 Bolfcio-Dcl«Msfctif Bbd-ehUrcdn

Aeainhg r.Un 23Travjar »n Blvd.

BC T2i SM +

Canada

■60+- S5-

■60+ 555-

BCi B/ Fi Btwrager MdoriaAfhwcrh

car:: Pfprtrtrd Farlerqr Clrcix

unun

EC2SNT

UK

C17 OSS-

CACTU Ca: U Can Mar paral PatldoCtnprori

Gate* Ag«nl Cirri b 333

Eueiw .'let

1010

Ameplm

CO l»55

(0 135+S

CE*rc Centoccnttrclal Mod Frandra:. Chmg

Mart* Inj r.laiM Sfcirar d«- Gur&iaiE

F.VJm tu .

03322

r.V'k •:■

CEJSS&33

■S" 55572

CHOPC Chop-iueyCllnae Yärig Wang

Owner HaLptet.23

Km

3012

Cwlbtriard

0+5MJ7&

conr.il CanirdoMhtio pfiiro Mmrci

Catei AHOdale .'•u. for Luriads ,23

3So Pat*:-

CP Oi+3Z-0+3 E-iadl

CIO »7

CONCH CawmaM Hddlyr Btd-«hBrovm

Cater RepreteriJ EifKifc-/ Garden

WMXI 6LT

UK

CI7 p Si-

(17 '(■ S5-

DP/CD Dradierfehil ['dl*: SutnOllltb

Ord«f ^lnJri: laVVdrerAtfl-l

Aachen

■SSM»

G<r manor

02+1-0»

02+1-055+

DUMO H Dumonlt «nler Join« Li-nrt

Owner 6-7, r« der Clrejusnte

Naik?:

++OÜD

Fr«e

+067 -S5.

Figure 25-3: The formatting result after implementing the Detail_Format event in Hands-On 25-8 is illustrated here.

The next hands-on demonstrates how to suppress the Page Footer on the first page of your report by placing code in the PageFooterSection_Format event procedure.

0 0

Post a comment