Creating Public Functions.

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

Guest

I am very very very novice at this, but here is what I attempted and it did
not wrok. Can you guide me:

Report:
Created a textbox with a with the control source as: TOCTitle()

Form:
Created a command button
On Click Event Procedure
Private Sub cmd2051f_Click()
strTOCTitle = "GF 20.5.1"
DoCmd.OpenReport "rptGFTOC",acViewPreview, "qryIdahoToc",
"gf_2051_frms_dist = yes"
End Sub

public strTOCTitle as string
public function TOCTitle() as string
TOCTitle = strTOCTitle
end function

What is wrong:

I click on the button and a Parameter Value dialog opens wanting a
value for TOCTitle().

Please help.

Thanks.
 
Is gf_2051_frms_dist the text box that has TOCTitle() as the control source?
Where are you passing the argument to TOCTTitle()?
 
Try placing the Public variable and function in a standard module (one that
you would create in the Modules tab of the main database window). The
variable declaration would go near the top where it says "Option Compare
Database" and hopefully says "Option Explicit". If that second line isn't
there, add it to each of your modules (standard and form/report). To have it
added automatically to all new modules, in the code editor go to
Tools|Options and check the box "Require Variable Declaration". This WILL
save you some debugging hassles in the future. When you save the module, it
must not be given a name of any other procedure, including the name of
procedures in the module. Instead, give it a descriptive name such as
basMyFunctions.

The reason for the prompt by the report is that the control source should be

=TOCTitle()

Note the added equals sign. Without it, the report is looking for a field
called TOCTitle() and when it doesn't find it, the report assumes it to be a
parameter and prompts you for it.

If the form is going to be open whenever this report is opened, you don't
need the function to pass the value. You could simply have the Control
Source point to the control on the form to get its value.

=Forms!frmMyForm!ctlMyControl

or you could have code in the report get the value from the Public variable
and assign that value to the control on the report. You could also pass the
value as the OpenArgs argument of the report (requires Access 2003) and have
the code in the report get the OpenArgs value and assign that to the
control.
 
Help!!!!

I can't figure out what I'm doing wrong. I've followed your instructions
and it doesn't work.

In the report I added the = sign to my control source.

=MyTitle

In the module I placed the public module

Option Compare Database
Option Explicit

Public strmytitle As String
Public Function mytitle() As String
mytitle = strmytitle
End Function

On the form I created the click event procedure:

Private Sub cmd2051f_Click()
strmytitle = "Great Falls 20.5.1"
DoCmd.OpenReport "rptGFTOC", acViewPreview, "qryIdahoToc",
"gf_2051_frms_dist = yes"
End Sub

Thanks for your help.
 
Sondra said:
Help!!!!

I can't figure out what I'm doing wrong. I've followed your
instructions and it doesn't work.

In the report I added the = sign to my control source.

=MyTitle

In the module I placed the public module

Option Compare Database
Option Explicit

Public strmytitle As String
Public Function mytitle() As String
mytitle = strmytitle
End Function

On the form I created the click event procedure:

Private Sub cmd2051f_Click()
strmytitle = "Great Falls 20.5.1"
DoCmd.OpenReport "rptGFTOC", acViewPreview, "qryIdahoToc",
"gf_2051_frms_dist = yes"
End Sub

PMFJI, but you're going to need to include the parentheses on the end of
your controlsource:

=MyTitle()
 
OOPs, forgot to add those in my post. I did enter the () in my control
source it looks like this

=myTitle()

But its not working. Any advise?

What is PMFJI
 
Sondra said:
OOPs, forgot to add those in my post. I did enter the () in my
control source it looks like this

=myTitle()

But its not working. Any advise?

What is PMFJI

"PMFJI" is short for "Pardon Me For Jumping In". Sometimes you'll see
just "PMJI" -- Pardon My Jumping In.

You'll need to tell us what you mean by "It's not working". What sort
of "not working"?
 
PMFJI = Pardon Me For Jumping In

Did you add the Option Explicit to the form module also? If not, strmytitle
may be misspelled there. Try doing a Compile and see if you get any errors.
In the code window go to Debug|Compile <name of your database>.

I just tried what you're doing with a textbox in the detail section of a
report and it showed the value for each record.
 
Sorry my error, I had done exactly what you identified I hadn't. Here is my
current structure:

Report

unbound text box control source: =mytitle()

Form:
on click event procedure

Private Sub cmd2051f_Click()
strmytitle = "Great Falls 20.5.1"
DoCmd.OpenReport "rptGFTOC", acViewPreview, "qryIdahoToc",
"gf_2051_frms_dist = yes"
End Sub

Standard Module name basmyfunction

Option Compare Database
Option Explicit

Public strmytitle As String
Public Function mytitle() As String
mytitle = strmytitle
End Function

It doesn't work. The report opens without the field being completed. I
don't know where I'm missing something that all of you had told me, but any
advise would be great.

Sondra
 
Sondra said:
Sorry my error, I had done exactly what you identified I hadn't.
Here is my current structure:

Report

unbound text box control source: =mytitle()

Form:
on click event procedure

Private Sub cmd2051f_Click()
strmytitle = "Great Falls 20.5.1"
DoCmd.OpenReport "rptGFTOC", acViewPreview, "qryIdahoToc",
"gf_2051_frms_dist = yes"
End Sub

Standard Module name basmyfunction

Option Compare Database
Option Explicit

Public strmytitle As String
Public Function mytitle() As String
mytitle = strmytitle
End Function

It doesn't work. The report opens without the field being completed.
I don't know where I'm missing something that all of you had told me,
but any advise would be great.

That all looks okay. The only thing I can think of offhand is that you
may also have declared a variable named "strmytitle" in the *form's*
module. If you did that, then your code would be setting *that*
variable and not the public variable in the standard module
"basmyfunction".
 
Back
Top