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!
Microsoft Access

Avatar of undefined
Last Comment
terpsichore

8/22/2022 - Mon
John Tsioumpris

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

terpsichore

ASKER
Thank you - how do I think reference that form+field to update it with a certain value, in the function?
John Tsioumpris

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
Experts Exchange is like having an extremely knowledgeable team sitting and waiting for your call. Couldn't do my job half as well as I do without it!
James Murphy
terpsichore

ASKER
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...
John Tsioumpris

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

terpsichore

ASKER
Also - when I'm passing the formname ('me'), I guess it is not fully referenced. Maybe this is part of the problem?
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
John Tsioumpris

Also to reference to a control from a frm object
frm.controls(thiscontrol.name)

Open in new window

terpsichore

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

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
SOLUTION
Dale Fye

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
terpsichore

ASKER
Definitely covered the waterfront - great responses from real experts. I am grateful.
All of life is about relationships, and EE has made a viirtual community a real community. It lifts everyone's boat
William Peck