Need to use public variable via function in form

  • Thread starter Thread starter laavista
  • Start date Start date
L

laavista

I wish to use a public variable in a form. I’ve read threads regarding this
and have tried everything I found with no luck

I have a public variable called intNumCredits. The variable is in a module
and is used in several procedures.

I have another module called “CreditsEntered†that contains the function

Public Function CreditsEntered() As Integer
CreditsEntered = intNumCredits
End Function

In my form, I used a text box. It’s called “text29†and its control source
is: =CreditsEntered()

I still get “#Name†error.

I checked the value of the public variable right before the form is brought
up and the value is there.

Thanks, in advance, for your help. I’m really stumped!
 
laavista said:
I wish to use a public variable in a form. I've read threads regarding
this
and have tried everything I found with no luck

I have a public variable called intNumCredits. The variable is in a
module
and is used in several procedures.

I have another module called "CreditsEntered" that contains the function

Public Function CreditsEntered() As Integer
CreditsEntered = intNumCredits
End Function

In my form, I used a text box. It's called "text29" and its control
source
is: =CreditsEntered()

I still get "#Name" error.

I checked the value of the public variable right before the form is
brought
up and the value is there.

Thanks, in advance, for your help. I'm really stumped!

VBA doesn't like module names that match function names within them. Rename
your module to (say) modCreditsEntered.
 
Stuart, you are brilliant! I tore my hair out over this (my hair used to be
down to my knees--now it is just below my ears!).

Thanks you for taking the time to help me with this. I'm fairly new to
Access VBA. I've created some modules and have named them modWhatEver, but
this was my 1st function, and for some reason I thought I had to name it the
same as the function.

Your correction worked!!

Again--THANK YOU.
 
laavista said:
Stuart, you are brilliant! I tore my hair out over this (my hair used to
be
down to my knees--now it is just below my ears!).

Thanks you for taking the time to help me with this. I'm fairly new to
Access VBA. I've created some modules and have named them modWhatEver,
but
this was my 1st function, and for some reason I thought I had to name it
the
same as the function.

Your correction worked!!

Again--THANK YOU.

You're welcome. Just to clarify, the name of a standard module is entirely
irrelevant to any VBA code. It's just for your benefit. The name of a class
module, however, is important because you use it to instantiate an object of
that class.
 
Back
Top