Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

passing control names as parameters

0 views
Skip to first unread message

waynemb

unread,
Nov 16, 2007, 12:51:01 AM11/16/07
to
I'm trying to pass different controls on an open form to an Access2003
function:

function (MyControlName as ???)

Forms!MyForm!MyControlName = "whatever"

end function

Thanks

Allen Browne

unread,
Nov 16, 2007, 1:18:03 AM11/16/07
to
You can pass a control name as a string if you wish:
Function AssignToControl(strFormName As String, strControlName As
String, varValue As Variant)
Forms(strFormName).Controls(strControlName) = varValue
End Function
Then use it like this:
Call AssignToControl("Form1", "Text0", 99)

That won't work with subforms, since the subform is not open in its own
right (i.e. it is not in the Forms collection.) Consequently, it might be
better to pass a reference to the control itself instead of using the form
and control names:
Function AssignToControl(ctl As Control, varValue As Variant)
ctl = varValue
End Function
And use it like this:
Call AssignToControl(Me.Text0, 99)

--
Allen Browne - Microsoft MVP. Perth, Western Australia
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.

"waynemb" <way...@discussions.microsoft.com> wrote in message
news:52CAB466-C7EB-4C36...@microsoft.com...

waynemb

unread,
Nov 16, 2007, 2:26:00 AM11/16/07
to
Thanks a million, that works perfectly.
0 new messages