I'm attempting to write a module in Access Basic for version 2.0, that I need to do the following:
* Cycle through all of the reports ;
* Cycle through the controls on each report to see if a control named "PSize"
exists ;
* If the "PSize" control doesn't exist, I need to create it.
My assumption when I started on this idea was that the each report document was actually a collection with all the controls attached. Am I totally
wrong in this assumption? It seems that is Access '97, the controls actually are part of
a collection for each report.
Does anyone know of any other way this can be done?
From: Shamil Salakhetdinov <shamil@marta.darts.spb.ru>
To: Microsoft Access Database Discussion List <ACCESS-L@PEACH.EASE.LSOFT.COM>
Subject: Re: Access 2.0: controls collection on reports?
Date: 22 April 1998 3:45
Robert,
Here is the code which I hope could be used as a template to
solve your task:
Sub CreatePSizeCtl ()
Dim dbs As Database ' Acc20
Dim con As Container
Dim doc As Document
Dim rpt As Report
Dim ctl As Control
'Dim fPsizeExists As Boolean ' Acc97
Dim fPsizeExists As Integer ' Acc20
Dim i As Integer, j As Integer, k As Integer
Set dbs = CodeDB() ' Acc20
'For Each con In CodeDb().Containers ' Acc97
For i = 0 To dbs.containers.count - 1 ' Acc20
Set con = dbs.containers(i) ' Acc20
If con.Name = "Reports" Then
'For Each doc In con.Documents ' Acc97
For j = 0 To con.documents.count - 1 ' Acc20
Set doc = con.documents(j) ' Acc20
DoCmd Echo False
'DoCmd.OpenReport doc.Name, acViewDesign ' Acc97
DoCmd OpenReport doc.Name, A_DESIGN ' Acc20
Set rpt = Reports(doc.Name)
fPsizeExists = False
'For Each ctl In rpt.Controls ' Acc97
For k = 0 To rpt.count - 1 ' Acc20
'Set ctl = rpt.controls(k) ' Acc97
Set ctl = rpt(k) ' Acc20
If ctl.Name = "PSize" Then
fPsizeExists = True
Exit For
End If
Next k
If Not fPsizeExists Then
'Set ctl = CreateReportControl(doc.Name, acTextBox, acDetail) ' Acc97
Set ctl = CreateReportControl(doc.Name, 109, 0) ' Acc20
ctl.Name = "PSize"
ctl.ControlSource = "=""DefaultPageSize"""
End If
'DoCmd.Close acReport, doc.Name, acSaveYes ' Acc97
DoCmd SetWarnings False ' Acc20
DoCmd Close A_Report, doc.Name ' Acc20
DoCmd SetWarnings True ' Acc20
DoCmd Echo True
'Next ' Acc97
Next j ' Acc20
End If
'Next ' Acc97
Next i ' Acc20
Set ctl = Nothing
Set doc = Nothing
Set con = Nothing
Set dbs = Nothing ' Acc20
End Sub
HTH,
Shamil
| HOME TOPICS |
Copyright © 19981999 by Shamil Salakhetdinov.
|
| Last updated: June 7, 1999 | |