Refer to form dynamically form a module (1 Viewer)

liddlem

Registered User.
Local time
Today, 19:27
Joined
May 16, 2003
Messages
339
Hi all
I have a few forms that call a function in a module.

The call is changeaddr(me.form.name)
However in the module I want test conditions and then (if required) change values on the form that made the call.

In short, the function looks like:

Function ChangeAddr(FN as String)

If Not IsNull(Forms!FN![Property_commune_Name]) Then'
End function

The error that I get is : Cannot find the form FN

So how would I put the form name in dynamically?
 

Uncle Gizmo

Nifty Access Guy
Staff member
Local time
Today, 19:27
Joined
Jul 9, 2003
Messages
16,279
What you do is you pass the form itself through as an object.

So where you have me.form.name you would just have me.form.

But that won't work unless you change the string variable that is currently accepting the form name into an object variable to accept the form.



Sent from my SM-G925F using Tapatalk
 

Uncle Gizmo

Nifty Access Guy
Staff member
Local time
Today, 19:27
Joined
Jul 9, 2003
Messages
16,279
Ah! I see the code now. What you are trying to do will work but you need to get the syntax right.

I was explaining a different way which will also work, but is unnecessary at the moment.

I can't remember the syntax off the top of my head. I think you put the form name in brackets but I can't check as I'm not by my PC at the moment.



Sent from my SM-G925F using Tapatalk
 

Uncle Gizmo

Nifty Access Guy
Staff member
Local time
Today, 19:27
Joined
Jul 9, 2003
Messages
16,279
Try something like:-

Forms(strFrmName).Property_commune_Name

Sent from my SM-G925F using Tapatalk
 

Uncle Gizmo

Nifty Access Guy
Staff member
Local time
Today, 19:27
Joined
Jul 9, 2003
Messages
16,279
Right I'm awake now! In my first answer I was thinking something like this:- Option Group Label Colour Change

In the video I demonstrate how it works and say a bit about the code the sample database attached contains the code however it's slightly modified from what appears in the video. A minor correction.
 

liddlem

Registered User.
Local time
Today, 19:27
Joined
May 16, 2003
Messages
339
Thanks Gizmo. The first suggestion worked a treat
 

StevePupel

New member
Local time
Today, 14:27
Joined
Nov 13, 2007
Messages
8
Its hard to tell, but I think the general technique could be better.

There's nothing wrong with passing a form reference, I do that all the time.

If you create the function like below, you could call the function out of an update query and update all or any subset or records in a table.

In this situation I'd rather do something like this ...

Create a function that accepts the string, and passes back a fixed up string. Then just set the control on the form equal to the value of the function.

ex.
' do whatever you need to do in the case it's null or an empty string ...
' this code would be in the form's module
Me!txtAddress1 = funFixAddress(me!txtaddress)

then in the global module ...
function funFixAddress(EntryString as string) as string

' do whatever string manipulation you need, then set funFixAddress to your new string.

end function
 

Users who are viewing this thread

Top Bottom