Easy question 
Author Message
 Easy question

Pardon my ignorance, but...

I have 2 modules that  work fine.  I want to execute one of them on a
form button click.  The other, I want to execute when a report is
printed.

To get the button click one to work, I
-made a macro that Ran the Code
-Attached the macro to the button OnClick event

Is that really necessary or is there a more direct way to attach a
module to a button?

How do I execute the other module when my report is printed?



Mon, 29 Sep 2003 04:29:12 GMT  
 Easy question
Renee,

There's no need to run a macro.

For the one you want executed when a button is clicked, add the function
name to the button's OnClick property (on the Property page), like so
(including the = sign):

    =MyFunctionName()

Keep in mind that the procedure MUST be a function, not a sub. To change it,
just change "Sub" to "Function", and don't worry about the return value.

For the other one, it depends on how you're calling the report. If you're
calling the report in VBA, simply put the procedure name after the
DoCmd.OpenReport... line. If you're calling it in a macro, do the following:

1. From the macro design view, select the View menu, then select Macro
Names. You'll notice a new column appear in the macro table.
2. In the Macro Name column, give the macro a name.
3. After the OpenReport action, add a RunCode action, giving your second
function name as the argument (with similar syntaxt as that shown above).
Note that it too must be a function, not a sub.

It should look something like this:
Macro Name       |     Action
--------------------------------
MyMacroName   | OpenReport
                            | RunCode

4. Save the macro.

Then go back to wherever you call this macro, and change the macro name to
the name you just gave it.

------
Graham R Seach MCP Microsoft Access
Pacific Database (Australia) Pty Limited

------


Quote:
> Pardon my ignorance, but...

> I have 2 modules that  work fine.  I want to execute one of them on a
> form button click.  The other, I want to execute when a report is
> printed.

> To get the button click one to work, I
> -made a macro that Ran the Code
> -Attached the macro to the button OnClick event

> Is that really necessary or is there a more direct way to attach a
> module to a button?

> How do I execute the other module when my report is printed?



Mon, 29 Sep 2003 08:46:53 GMT  
 Easy question
Thanks, Graham.
Quote:

> Renee,

> There's no need to run a macro.

> For the one you want executed when a button is clicked, add the function
> name to the button's OnClick property (on the Property page), like so
> (including the = sign):

>     =MyFunctionName()

> Keep in mind that the procedure MUST be a function, not a sub. To change it,
> just change "Sub" to "Function", and don't worry about the return value.

> For the other one, it depends on how you're calling the report. If you're
> calling the report in VBA, simply put the procedure name after the
> DoCmd.OpenReport... line. If you're calling it in a macro, do the following:

> 1. From the macro design view, select the View menu, then select Macro
> Names. You'll notice a new column appear in the macro table.
> 2. In the Macro Name column, give the macro a name.
> 3. After the OpenReport action, add a RunCode action, giving your second
> function name as the argument (with similar syntaxt as that shown above).
> Note that it too must be a function, not a sub.

> It should look something like this:
> Macro Name       |     Action
> --------------------------------
> MyMacroName   | OpenReport
>                             | RunCode

> 4. Save the macro.

> Then go back to wherever you call this macro, and change the macro name to
> the name you just gave it.

> ------
> Graham R Seach MCP Microsoft Access
> Pacific Database (Australia) Pty Limited

> ------



> > Pardon my ignorance, but...

> > I have 2 modules that  work fine.  I want to execute one of them on a
> > form button click.  The other, I want to execute when a report is
> > printed.

> > To get the button click one to work, I
> > -made a macro that Ran the Code
> > -Attached the macro to the button OnClick event

> > Is that really necessary or is there a more direct way to attach a
> > module to a button?

> > How do I execute the other module when my report is printed?



Mon, 29 Sep 2003 23:17:59 GMT  
 Easy question
If the code is simple,  I build it as a "Form" module.  Especially if the
code ONLY is needed when that button is clicked.  Then I include all the
code in the OnClick event.  I don't think there's a wizard for running code.
Sometime,  I use the wizard to get the pre-coding for errror trapping. Then
delete all the code and put the code I want in there.  If you need it as a
Module, just use this statement in your OnClick event:

Call "subName"  'where subName is the name of the subroutine you want to run

Same as for onPrint event I believe (Although I never did this).

Jim


Quote:
> Pardon my ignorance, but...

> I have 2 modules that  work fine.  I want to execute one of them on a
> form button click.  The other, I want to execute when a report is
> printed.

> To get the button click one to work, I
> -made a macro that Ran the Code
> -Attached the macro to the button OnClick event

> Is that really necessary or is there a more direct way to attach a
> module to a button?

> How do I execute the other module when my report is printed?



Tue, 30 Sep 2003 10:35:29 GMT  
 Easy question
Thanks, James.
Quote:

> If the code is simple,  I build it as a "Form" module.  Especially if the
> code ONLY is needed when that button is clicked.  Then I include all the
> code in the OnClick event.  I don't think there's a wizard for running code.
> Sometime,  I use the wizard to get the pre-coding for errror trapping. Then
> delete all the code and put the code I want in there.  If you need it as a
> Module, just use this statement in your OnClick event:

> Call "subName"  'where subName is the name of the subroutine you want to run

> Same as for onPrint event I believe (Although I never did this).

> Jim



> > Pardon my ignorance, but...

> > I have 2 modules that  work fine.  I want to execute one of them on a
> > form button click.  The other, I want to execute when a report is
> > printed.

> > To get the button click one to work, I
> > -made a macro that Ran the Code
> > -Attached the macro to the button OnClick event

> > Is that really necessary or is there a more direct way to attach a
> > module to a button?

> > How do I execute the other module when my report is printed?



Tue, 30 Sep 2003 21:20:13 GMT  
 Easy question
Graham, I am about to jump out of a window.  Teaching yourself VB from a
book with deadlines breathing down your neck is far from efficient, but
I'm afraid it's my only option.  Last week you answered a question for
me regarding how to call a user defined public function to an on click
event.

You said that the button's on click property should be set to
=MyFunctionName ().  Currently I'm getting an error that reads, " The
expression On Click you entered as the event property setting produced
the following error:  The expression you entered has a function name
that Microsoft Access can't find."

Would you pretty please look at the code below and see if you can tell
me what I'm missing?  I am truly puzzled.  When I was testing this
function, I used the run button in the module and it worked.  I closed
Access and Word, without changing anything.  When I went back to the
project later, opened the module and hit run, nothing happens.  This is
the kind of stuff that makes me nuts.  I'm sure there is some perfectly
logical explaination, but darned if I know it.  I decided to attach it
to a form button to test, now I get the error above.

On Click is set to "=Template()"
Here is the code:

Option Compare Database
Option Explicit

Private objWordApp As Word.Application

              Function Template()
                Const conTEMPLATE_NAME = "K:\Philips
Lighting\Letters\Solicitation Form Letter.dot"

                   Set objWordApp = New Word.Application
                   With objWordApp
                      .Visible = True
                      .WindowState = wdWindowStateMaximize
                      .Documents.Add Template:= _
                      "K:\Philips Lighting\Letters\Solicitation Form
Letter.dot", NewTemplate:=False
                   End With
                End Function

Quote:

> Renee,

> There's no need to run a macro.

> For the one you want executed when a button is clicked, add the function
> name to the button's OnClick property (on the Property page), like so
> (including the = sign):

>     =MyFunctionName()

> Keep in mind that the procedure MUST be a function, not a sub. To change it,
> just change "Sub" to "Function", and don't worry about the return value.

> For the other one, it depends on how you're calling the report. If you're
> calling the report in VBA, simply put the procedure name after the
> DoCmd.OpenReport... line. If you're calling it in a macro, do the following:

> 1. From the macro design view, select the View menu, then select Macro
> Names. You'll notice a new column appear in the macro table.
> 2. In the Macro Name column, give the macro a name.
> 3. After the OpenReport action, add a RunCode action, giving your second
> function name as the argument (with similar syntaxt as that shown above).
> Note that it too must be a function, not a sub.

> It should look something like this:
> Macro Name       |     Action
> --------------------------------
> MyMacroName   | OpenReport
>                             | RunCode

> 4. Save the macro.

> Then go back to wherever you call this macro, and change the macro name to
> the name you just gave it.

> ------
> Graham R Seach MCP Microsoft Access
> Pacific Database (Australia) Pty Limited

> ------



> > Pardon my ignorance, but...

> > I have 2 modules that  work fine.  I want to execute one of them on a
> > form button click.  The other, I want to execute when a report is
> > printed.

> > To get the button click one to work, I
> > -made a macro that Ran the Code
> > -Attached the macro to the button OnClick event

> > Is that really necessary or is there a more direct way to attach a
> > module to a button?

> > How do I execute the other module when my report is printed?



Sun, 05 Oct 2003 22:44:57 GMT  
 
 [ 7 post ] 

 Relevant Pages 

1. EASY EASY EASY question

2. help easy easy question

3. easy question

4. bitmaps, easy question

5. Public functions, easy question

6. I'm sure that this is an easy question

7. easy question

8. help new to VBA, easy question

9. quick and easy question....please help!

10. How does A2K handle ASP - Many Easy Questions

11. easy question

12. Easiest question of the week...

 

 
Powered by phpBB® Forum Software