Calling a function in opening a form

  • Thread starter Thread starter Arvin Villodres
  • Start date Start date
A

Arvin Villodres

I'm trying to call a function from the class module
whenever I try to
open a form. But somehow the form that was opened does not
perform the
function I'm trying to call. My code goes like this:

*The function I'm trying to call.
Public Function Identify()
If txtUserName = "Administrator" Then
me.AllowEdits = True
Else
me.AllowEdits = False
End If
End Function

*The code in the form that is being opened. This form has
a text box (txtUserName)identifying the user.

Private Sub Form_Open(Cancel As Integer)
hello
End Sub

When I try to debug it the note that is being seen on the
txtUserName of the function Identify
when the focus is on it says "txtUserName = Empty"

Please help me with this one. I'm still not that familiar
with class Modules. or calling a function.

Thanks for the help.

Arvin Villodres
 
Your function is not returning a value. By definition,
functions return a value, whereas subroutines or
subprocedures do not. Try it this way:
-----------------------------------------------------
Public Function Identify(varUName as Variant) as Boolean
If varUName = "Administrator" Then
Identify = True
Else
Identify = False
End If
End Function
-----------------------------------------------------
In the form where you're calling the function, this is
what your line of code will look like (there are several
ways in which to call a function, but this is my personal
preference).
Call moduleName.Identify(Me.txtUserName.value)

Regards,
Jen
 
Back
Top