Why I can't find the second report which created in the Access in

S

Shimmey

In Access. I created one form and report, and then I can find them in the
VBA. Also, I can use them as objects with Form_*** or Report_***.
But when I created the second report and form, I can't find them in the VBA.
Why?
And I can't use them as object.
Maybe need to define them as global variable...
I don't know. Who can tell me sth about that? How to solve this problem?
Thanks for all!
 
B

Brendan Reynolds

Shimmey said:
In Access. I created one form and report, and then I can find them in the
VBA. Also, I can use them as objects with Form_*** or Report_***.
But when I created the second report and form, I can't find them in the
VBA.
Why?
And I can't use them as object.
Maybe need to define them as global variable...
I don't know. Who can tell me sth about that? How to solve this problem?
Thanks for all!


What you see in the VBA editor is not actually the form or report itself,
but the class module associated with the form or report. A form or report
with no code has no class module.
 
S

Shimmey

--
Lee Shimmey


Brendan Reynolds said:
What you see in the VBA editor is not actually the form or report itself,
but the class module associated with the form or report. A form or report
with no code has no class module.
And if I want to use a button to print the second report, but before print I
need to add data to it by code. The problem is--I can't visit the object in
it, there's error: Object required! Because there's not module in the VBA
environment.
How can I create the module by mamually? Or add the code into the report? Is
there any way else?
Thanks!
 
M

Marshall Barton

Shimmey said:
In Access. I created one form and report, and then I can find them in the
VBA. Also, I can use them as objects with Form_*** or Report_***.
But when I created the second report and form, I can't find them in the VBA.
Why?
And I can't use them as object.


For some very subtle reasons, you should not use that
syntax, except when you are opening multiple instances of
the same form/report. Since that is a very afvanced thing
to do, I think it's fair to say that you should not use it
at all.

Instead you should use the standard, every day syntax:

Forms![name of form]

This syntax allows you to get to the form object without
concern whether it has a module or not.
 
B

Brendan Reynolds

And if I want to use a button to print the second report, but before print
I
need to add data to it by code. The problem is--I can't visit the object
in
it, there's error: Object required! Because there's not module in the VBA
environment.
How can I create the module by mamually? Or add the code into the report?
Is
there any way else?
Thanks!

I'm not sure what you mean by 'add data to the report'. Usually, if you want
data to appear in a report, you add it to the table or tables to which the
report is bound. If you want to display some text in a report that is not
stored in a table, there are various ways of doing that, for example you can
use an expression as the control source of a text box in a report that might
retrieve data from a text box in an open form or from a custom VBA function.
For example, to display data from a text box in an open form, the expression
might look like this ...

=Forms!NameOfYourFormHere!NameOfYourTextBoxHere

To display the result of a function, the control source might look like this
....

=NameOfYourFunctionHere()

See also Marshall's post elsewhere in this thread. Generally speaking, most
things you are likely to want to do can be done by referring to the report
itself, rather than the report's class module. I can't remember ever having
a need to refer to a report's class module.
 
S

Shimmey

Well, I'm back from a short vacation now.
Thanks to all of your answer, I solved my problem.
To show the report in the VBA environment, an empty sub added in it.
I want to statistic the count of the records in the database, so have to
create the data by coding. Now I made it, and your information gave a great
help to me!
Thanks very much!
--
Lee Shimmey


Marshall Barton said:
Shimmey said:
In Access. I created one form and report, and then I can find them in the
VBA. Also, I can use them as objects with Form_*** or Report_***.
But when I created the second report and form, I can't find them in the VBA.
Why?
And I can't use them as object.


For some very subtle reasons, you should not use that
syntax, except when you are opening multiple instances of
the same form/report. Since that is a very afvanced thing
to do, I think it's fair to say that you should not use it
at all.

Instead you should use the standard, every day syntax:

Forms![name of form]

This syntax allows you to get to the form object without
concern whether it has a module or not.
 

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

Top