Link to home
Start Free TrialLog in
Avatar of terpsichore
terpsichore

asked on

easy one - pass form and field to function

Dear experts -
I want to pass the current form name and the name of a text box (field) on that form to a function.
I then want the function to do certain things and in certain cases update that field.

How do I properly pass the form and field name, and then how do I properly reference them in the function?
Thanks!
Avatar of John Tsioumpris
John Tsioumpris
Flag of Greece image

Public Function YourFunction (frm as form,TextBoxValue as string)

Open in new window


You call it like this
YourFunction Me, Me.textbox.name

Open in new window

Avatar of terpsichore
terpsichore

ASKER

Thank you - how do I think reference that form+field to update it with a certain value, in the function?
I am not 100% percent sure what you need,,,
I assume that you want to perform some operations in your function that will affect your form....
if this is correct then you need to modify the function to  like this
Public Function YourFunction (ByRef frm as form,TextBoxValue as string)

Open in new window

but better to give some more info about your function
I'm trying to do something like this in the function, but it is giving me an error:

Function ShowLink(thislink As String, thisform As Form, thiscontrol As String)

Dim sFilename as string
sFileName = Mid(thislink, iBackslash + 1, (Len(thislink) - iBackslash))
thisform.thiscontrol = sFileName

On the last line above, I'm getting error 2465, Application-defined or object-defined error...
Function ShowLink(thisLink as string) as string
ShowLink=  = Mid(thisLink , iBackslash + 1, (Len(thislink) - iBackslash))
End function

Open in new window

Then on the control you want to use it
me.thiscontrol = showlink(thisLink )

Open in new window

Also - when I'm passing the formname ('me'), I guess it is not fully referenced. Maybe this is part of the problem?
Also to reference to a control from a frm object
frm.controls(thiscontrol.name)

Open in new window

sorry, I'm still not getting this. can you pls be more specific on how I should correct the error?
Thanks!
ASKER CERTIFIED SOLUTION
Avatar of John Tsioumpris
John Tsioumpris
Flag of Greece image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Definitely covered the waterfront - great responses from real experts. I am grateful.