Find & Replace in Report control source

A

azu_daioh

I have a report with over 300 unbound text box with the following
control source:
=DCount("[EntryDate]","[ID Flag Imported]","[FO_ID]=1 And
Year([EntryDate])=[GetYear] And Month([EntryDate])=4")


Now I need to change [ID Flag Imported] to [ID Flag]

Is there an easier way to change all the unbound text boxes control
source without doing it one at a time? I tried one of the codes I
found here but I couldnt get it to work

-----------------
Dim ctl As Control, strReportName As String
strReportName = "rptReportName"
DoCmd.OpenReport strReportName,acViewDesign,,,acHidden
For Each ctl In Reports(strReportName).Controls
If InStr(ctl.ControlSource, "Forms!Form1") > 0 Then
ctl.ControlSource = Replace(ctl.ControlSource, "Forms!Form1",
"Forms!Form2")
End If
Next
DoCmd.Close acReport, strReportName, acSaveYes
---------------------

The name of my report is "Monthly ID Flag count by FO"

so I replaced "rptReportName" by "Monthly ID Flag count by FO"
replaced "Forms!Form1" with "[ID Flag Imported]"
replaced "Forms!Form2" with "[ID Flag]"

and I pasted the code after I clicked the "code" tool from the report
design view

Please help. I have 2 reports I need to replace the control source and
the other is another 300+ text boxes. :(

Thank you,
Sharon
 
A

azu_daioh

I'm getting this error message:

Run Time error 438, Object doesnt support this property or method
 
A

azu_daioh

Thanks. But unfortunately, our admin does not allow us to install
anything at work.
 
B

Brendan Reynolds

The code you posted earlier looks to me like it should work. Perhaps if you
post your modified version, and describe what happens when you run it,
someone might be able to see what the problem is.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top