Passing form field to function

C

cherman

How can I pass a reference of a form to a function in a way that will let me
set a text box value and propertie on that form from within the function?

Thanks!
 
A

Allen Browne

Declare the function like this:
Function DoSomething(txt As TextBox)

Call it like this:
Call DoSomething(Me.[Text99])
 
O

Ofer Cohen

I hope I unerstand your question

A function that get two parameters: form name and field name and set a value
to it

Function SetField(FormName As String, FieldName As String)

Forms(FormName)(FieldName) = "aaaaa"

End Function
=====================
To call the function and pass values

SetField "MyFormName", "MyFieldName"
 
C

cherman

Thanks, and sorry for the lack of info. I was a little wiped out when I
posted this.

I was able to use your solution to set the value of the field but I cannot
chage the ForeColor of the field.

I tried Forms(FormName)(FieldName).ForeColor = 255 but it didn'd do
anything. Is there a different format for setting properties?

Thanks,
Clint
 
O

Ofer Cohen

Hi, sorry it took me a while to come back to you.
It should work just the same, I tried it and it colored my text box text in
red.

Do you still got a problem
 
Top