HandsOn Writing the Detail

This hands-on uses the rptCustomers report you created in Hands-On 25-1.

1. Open the rptCustomers report in the Design view and place two unbound text boxes in the report's page footer.

Change the Name property of the first box to txtPage and set its Visible property to No. Delete the label control in front of this text box. Name the second text box txtRange and set the Caption property of its label control to Records:.

2. Click in the Detail section of the report and activate the properties sheet. Set the On Print property of the Detail section to [Event Procedure] and write the code for the Detail_Print event as shown below.

Private Sub Detail_Print(Cancel As Integer, _ PrintCount As Integer) Static rCount As Integer Static start As Integer Static firstId As String Static lastId As String

If Me.Page <> Me.txtPage Then start = Me.CurrentRecord firstId = CustomerID Me.txtPage = Me.Page rCount = 0 End If rCount = rCount + 1 lastId = CustomerID If start <= rCount Then

Me.txtRange = start & "-" & rCount ' Me.txtRange = UCase(firstId) & "-" & UCase(lastId) Else rCount = Me.CurrentRecord lastId = CustomerID End If End Sub

The Detail_Print event procedure occurs for each record. It uses the start and rCount variables to keep track of the first and last item on the page.

3. In the Code window, enter the PageHeaderSection_Print event procedure as shown below.

Private Sub PageHeaderSection_Print(Cancel As Integer, _

PrintCount As Integer)

Me.txtPage = 0 End Sub

4. To test the above event procedure, open rptCustomers and click the Print Preview button on the toolbar. Notice the record range indicator at the bottom of the report page.

Part IV

The PageHeaderSection_Print event procedure will set the value of the unbound txtPage text box to zero (0) whenever the Print event occurs for a new page.

BOLID Boiidn Cornidae prepar MaMin Sommer Owner C/Araquil, 67 Madrid -^J

BONAP Bon app'

Laurence Lebihan

Owner 12, rue des Bouchers

Marseille

BOTTM Bo!tom-Dollar Markets

Elizabeth Lincoln

Accounting Man 23 Tsawassen Blvd.

Tsawassen

BSBEV B's Beverages

Victoria Ashworth

Sales Represent Fauntleroy Circus

London

CACTU Cactus Comidas para 1 Patricio Simpson

Sales Agent Cerrito333

Buenos Aires

CENTO Centro comercial Mod Francisco Chang

Ma rketing Man a Si e rra s de G ran a d a 99

Mexico D.F.

CHOPS Chop-suey Chinese

Yang Wang

Owner Hauptstr. 29

Bern

CQMMI ComSrcio Mineiro

Pedro Afonso

Sales Associate Av. dos Lusiadas.23

Slo Paulo

CONSH Consolidated Holdings

Elizabeth Brown

Sales Represent Berkeley Gardens

London

DRACD Drachenblut Delikates

Sven Ottlieb

Order Administra Walserweg 21

Aachen

DU MOM Du rnonde entier

Janine Labrune

Owner 67, rue des Cinquante

Nantes

Saturday, July 31, 2004

Records:

1-18

Figure 25-4: This report displays the record range indicator at the bottom of the page (see Hands-On 25-10).

You can modify the event procedure in Hands-On 25-10 to print the first and last customer ID on the page as shown in Figure 25-5. Simply replace the following statement in the Detail_Print event procedure

Me.txtRange = start & "-" & rCount with the following line of code

Me.txtRange = UCase(firstld) & "-" & UCase(lastld)

M

BOLID

Bólido Comidas prepar Martin Sommer

Owner C/Araqui!,67

Madrid

BONAP Bon app1

Laurence Leb than

Owner 12, rue des Bouchers

Marseille

BOTTM

Boltom-Dollar Markets Elizabeth Lincoln

Acc ou nt in g Ma n 23Teawassen Blvd.

Tsawassen

BSBEV

B's Beverages

Victoria Ashworth

Sales Represent Fauntleroy Circus

London

CACTU

Cactus Comidas para 1 Patricio Simpson

Sales Agent Cerrito333

Buenos Aires

CENTC

Centro comercial Mo ci Francisco Chang

Marketing Mana Sierras de Granada S9

Mexico D.F-

CHOPS

Chop-suey Chinese

Yang Wang

Owner Hauptslr. 29

Bern

COMMI

Comércio M in ei ra

Pedro Afonso

Sa les Asso cial e Av d os Lu sia das, 23

Sao Paulo

CONSH

Consolidated Holdings

Elizabeth Brown

Sales Represent Berkeley Gardens

London

DRACD

Drachenblut Delikates

Sven Ottlieb

Order Admrnislra Walserweg 21

Aachen

DU MON Du rnonde entier

Janine Labrune

Owner 67, rue des Cinquante

Nantes

Saturday, July 31 2004

Records:

ALFKI-DUMON

Figure 25-5: This report displays the first and last customer ID for a specific page at the bottom of each printed page.

Event Programming in Forms and Reports

0 0

Post a comment