Help With Public Function

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hello to all,

I created the following function in my main form called "Switchboard":

Public Function GetAgentName() As String
GetAgentName = "John Doe"
End Function

I'm trying to use this function to update text boxes contained in all my
forms and reports. The control source of each text box in all reports and
forms has this reference:

=GetAgentName()

The function call works fine in the main "Switchboard", but it does not work
in other forms or reports. In the other reports I get this popup message:

Enter Parameter Value

According to Access Help Section, anything defined as public is supposed to
be "available to all procedures in all modules in all applications unless
Option Private Module is in effect", which it's not.

What's up with this?
 
Put the function in a regular module so that it's available all the time for
all other code to use. Delete it from the switchboard form's module.
 
Sky said:
I created the following function in my main form called "Switchboard":

Public Function GetAgentName() As String
GetAgentName = "John Doe"
End Function

I'm trying to use this function to update text boxes contained in all my
forms and reports. The control source of each text box in all reports and
forms has this reference:

=GetAgentName()

The function call works fine in the main "Switchboard", but it does not work
in other forms or reports. In the other reports I get this popup message:

Enter Parameter Value

According to Access Help Section, anything defined as public is supposed to
be "available to all procedures in all modules in all applications unless
Option Private Module is in effect", which it's not.

What's up with this?


The rule about Public functions as you stated only applies
to functions in Standard Modules. It's different for
functions in Class Modules (including Form/Report modules)

Move the function to a Standard Module and it should work as
expected.
 
Ken, Marshall

Ummm dudes, I don't know the difference between standard, regular or any
other module, I just know module. Can you show my remedial butt an example of
what you mean :-(

-Sky
 
A regular module is one you can "see" in the database window when you click
Modules as the object type. A form's module is associated to the form (it's
actually a class module) and cannot be "seen" except through the form.
 
Ken,

OK, I created a new module and put the GetAgentName() public function inside
it. I then deleted the function from my Switchboard form.

Everything works perfectly now. All my reports and forms are updated
immediately on open.

Ken, if you look very carefully you can see me on the floor bowing down and
paying worship to the MVP's of Office Access :-)

YOU GUYS ROCK!!! Thanks for all your help, I owe you big time.

-Sky
 
Hello Ken and Marshall

I was searching through old posts and this one answered part of my question
about standard modules. I don't know if its possible or I dont know how to do
it, but my question is: Is it possible to load the value or text "John Doe"
(GetAgentName()) using an event procedure on the form. Possibly by using the
Form Load event? I know that Sky was using the control source to load the
value or text "John Doe" (GetAgantName())? Why would I want to do this?
Because, I would like to get comfortable writing as much code as possible. So
my approach would possibly be something like this:


Private Sub Form_Load()

Me.Text2.Text = GetAgentName()

End Sub

My next question is when I creat a standard module, why is it not displayed
in the module window? It is dispaying in the object browser but not in the
module window?

Thanks In advance
kw_uh97
 
After some trials and errors I solvedf both of my questions.

The first make use of the explanation point (!)

Me!Text2 = GetAgentName()

The second click the save button in the VB IDE and it will be displayed in
the module window.

Thanks Again
kw_uh97

Me!Text2 = GetAgentName()
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top