create macro to open a userform when opening a database file

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

Guest

I am attempting to create a macro which automatically opens a userform when
one opens the database. I believe the macro needs to be named "AutoOpen" but
I am having problems setting up the macro. The existing userform
automatically opens when I invoke the macro named "Private Sub
CmdPrintReport_Click()" by going into the VB editors and "running" the
subroutine from there. Unfortunately, when I attempt to set up the macro
using the MACRO tab (as directed), I can't actually see this routine listed
as an available option.

How do I get this subroutine (which essentially calls up userform1) to be
the first thing one sees when opening the database file?
 
Thanks, Steve, for your prompt response, but I can't even access the macro
when I open the tab listed "macros"; I think it's because the subroutine is
associated with a userform and is called "Private Sub
CmdPrintReport_Click()". What is the "Action" command one should use in the
macro section to invoke a private macro? The procedure is not even showing
up in the "macro name box" of the macro tab.... could that be because the
procedure is "private" or because it's associated with a userform? The only
way I can invoke it is by "running" it directly from the VBA section.
 
Eric,

In Access, macros and VBA have nothing to do with each other. It now
sounds like you have a VBA procedure set up to open the form. In order
to do what you are after, you have two choices. One is to make a macro,
with an OpenForm action, to open the required form. Then save the macro
and name it AutoExec.

There is nothing you can do here related to the form's module, as this
will only be available once the form is opened, whereas you are trying
to open the form, so obviously it isn't open yet.

Your other choice is to go to the Tools|Startup menu of the database,
and set there the name of the form in the Display Form/Page box.
 
Steve,
Thanks for your assistance. Unfortunately, either method doesn't appear to
work because the 'form' I wish to call up is a "USERFORM" and not a "Form".
The selection of options drop-down window is blank when I click on "form"
because it isn't a form as defined by the list of options available (wuch as
TABLES, REPORTS, QUERIES, FORMS, MACROS, etc.) I wish to call up a USERFORM1
which I created.

This seems odd to me..... Thanks.
 
Eric,

Can you please explain more about what you mean by "userform". I am
aware of this term in the context of Word and Excel, but not in Access.
 
Sure, Steve.

By USERFORM, I am referring to a user-designed form on which a user can add
blank fields to capture data input such as text boxes and option buttons.
Within the VB editor (design mode), the list of objects appears as follows:
- name of database
- Microsoft Access Class Objects (this is one module)
- Form_[Name of Form1]
- Report_[Name of Report1]
- Report_[Name of Report2]
- Report_ etc.
- Forms (a different module)
- Userform1
- Modules

The code I am attempting to execute is associated with Userform1 (i.e. an
input screen I designed by using the commands "insert userform") and allows
me to add customized boxes which capture input which I can later use by using
"textbox1.value", etc.

The code I wish to execute is in a PUBLIC SUB referred to as Public Sub
CmdPrintReport_Click() but when I attempt to execute this subroutine, it
appears that it cannot be accessed as it appears in a different module. How
can I access this subroutine (saved behind a "USERFORM" even if I create a
regular "FORM" which appears to only be able to access subroutines saved in
the same module?
 
Eric,

Well, you sure seem to have pulled an interesting one out of the hat
here. The concept of a userform in Access is pretty much unheard of,
but I have managed to ascertain that via a very obscure process, and
with a very unusual reference being set within the VBA project to
Microsoft Forms 2.0 Object library, it is possible to do as you suggest.
I can think of no practical purpose that could be served by doing so,
as an alternative to a proper Access form.

And yes, you can run a public subroutine from another form's module.
Perhaps you could provide more explicit details of your code, and what
you actually want to achieve, if you still need more help with this.
 
Back
Top