-----Original Message-----
I have a page that has 184 controls on it which are just
going to be for display (not input). At present each
control has a field data source. I need to change the
data source instead to a function call with the current
field being a parameter in the call. I don't want to have
to make changes in the properties window 184 times. Is
there a way to get at the controls like there is with
Queries and the SQL display mode or something like it?
Thanks.
184 data controls on one form! Yow! What is this form doing, if I may
ask?
You could run a subroutine something like this (WARNING -- AIR CODE):
'----- start of code -----
Sub FixControlSources(FormName As String)
Dim frm As Form
Dim ctl As Control
Dim strCtlSource As String
DoCmd.OpenForm FormName, acDesign, _
WindowMode:=acHidden
Set frm = Forms(FormName)
On Error Resume Next
For Each ctl In frm.Controls
strCtlSource = vbNullString
strCtlSource = ctl.ControlSource
If Len(strCtlSource) > 0 Then
' ctl is not unbound
If Left(strCtlSource, 1) <> "=" Then
' ctl is not calculated, so it must be bound.
' Add brackets if not already present, just in
' case.
If Left(strCtlSource, 1) <> "[" Then
strCtlSource = "[" & strCtlSource & "]"
End If
' Change the controlsource of ctl to a
' function call.
ctl.ControlSource = _
"=fncMyFunction(" & strCtlSource & ")"
End If
End If
Next ctl
Set frm = Nothing
DoCmd.Close acForm, FormName, acSaveYes
MsgBox "Finished fixing form " & FormName & "."
End Sub
'----- end of code -----
Note that you would want to modify the statement
ctl.ControlSource = _
"=fncMyFunction(" & strCtlSource & ")"
to call the function you had in mind.
Having saved the above routine in a standard module, you could call it
from the Immediate window:
FixControlSources "MyFormName"
--
Dirk Goldgar, MS Access MVP
www.datagnostics.com
(please reply to the newsgroup)
.