View Full Version : Setting ControlSource on Report Using Tags


Capilano
04-04-2001, 12:01 PM
I am trying to set the "Control Source" property for a group of controls on a report using the OnOpen event. This is an easy
task individually, however, I want to do this in a module through the use of the "Tag" feature. ie if Control.Tag > 3 then
ControlSource = Empty or Nothing. This way if I assign tags to controls, I can collectively leave the ControlSource as the
default or as an unbound Control on the Report. Why do I want to do this in a module? Because several of my reports use a
single 'template' report which has a standardized 12 Column capability. By default on the Report, all columns have bound
ControlSources (C1, C2, C3,... etc.) . However, if the underlying crosstab query only uses columns C1 to C7, the report will
error out unless I unbind (if there is such a word) Columns C8 to C12. This way when I open my report, it will not error out
because it cannot find a column C8 in the underlying query. I have set my recordsets properly and I have achieved this:

Dim db As DAO.Database, rec As DAO.Recordset, rec1 As DAO.Recordset
Set db = CurrentDb()
Set rec = db.OpenRecordset("RptCriterion")
Set rec1 = db.OpenRecordset("RecordSource set here;")

Dim rpt As Report
Set rpt = Reports(rec1![Report_Name])

Select Case rec.RecordCount
Case 1
rpt![GT1].ControlSource = Empty
rpt![GT2].ControlSource = Empty
rpt![GT3].ControlSource = Empty
rpt![GT4].ControlSource = Empty
rpt![GT5].ControlSource = Empty
rpt![GT6].ControlSource = Empty
rpt![GT7].ControlSource = Empty
rpt![GT8].ControlSource = Empty

And so forth... but I have a very long module with 12 Select Case scenarios.

Can I reduce this using a For each, Next Loop and if so how? Remember, I would like to use this in a Module which is called on the OnOpen event of a REPORT.

Thanks very much... I really appreciate it

Pat