Function in several forms

N

News

I have several forms wich all use the same function, like below. Now I want
to put the function in a module and call the function from each form. But
when I do so, the function does not knows what me![Titels voor] is, because
it is not in the module.
How can I make the function work from each form?

Function Maak_Voorafnaam()
Maak_Voorafnaam = ""
If IsNull(me![Titels voor]) Then
Maak_Voorafnaam = Maak_Voorafnaam & ""
Else
Maak_Voorafnaam = Maak_Voorafnaam & me![Titels voor] & " "
End If
If IsNull(me![Alle Voorletters]) Then
Maak_Voorafnaam = Maak_Voorafnaam & ""
Else
Maak_Voorafnaam = Maak_Voorafnaam & me![Alle Voorletters] & " "
End If
End Function
 
A

Allen Browne

Pass a reference to the form, and use that reference in your code, like
this:

Function Maak_Voorafnaam(frm As Form)
If IsNull(frm![Titels voor]) Then

Then call it as:
Call Maak_Voorafnaam(Me)
or if you need to use the function in the event property directly:
=Maak_Voorafnaam([Form])
 
R

Ron Weiner

Pass the value of me![Titels voor] and me![Alle Voorletters] as parameters
to the function. modify the function thusly.

Function Maak_Voorafnaam(varTV as Variant, varAV as Variant) as String
Maak_Voorafnaam = ""
If IsNull(varTV) Then
Maak_Voorafnaam = Maak_Voorafnaam & ""
Else
Maak_Voorafnaam = Maak_Voorafnaam & varTV & " "
End If
If IsNull(varAV) Then
Maak_Voorafnaam = Maak_Voorafnaam & ""
Else
Maak_Voorafnaam = Maak_Voorafnaam & varAV & " "
End If
End Function
 
M

MacDermott

Both the above suggestions will work fine.
If you always want to call the function from the active form, you can also
use Screen.ActiveForm instead of Me.
 
Top