Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

is it better to convert macros into modules?

Status
Not open for further replies.

GreekPatriot

Technical User
Nov 16, 2004
91
CY
this is a general sort of question.

What are the advantages and disadvantages of converting macros to modules (functions)???

Another question is. What are the differences between modules and subroutines? Can a module be converted to a subroutine?????

For example can this be converted to a subroutine?? Cheers
Option Compare Database

'------------------------------------------------------------
' Quit
'
'------------------------------------------------------------
Function Quit()
On Error GoTo Quit_Err

DoCmd.Quit acSave

Quit_Exit:
Exit Function

Quit_Err:
MsgBox Error$
Resume Quit_Exit

End Function
 
Hi,
Here is my knowledge
1) Code is running faster than macro
2) You can do all that with code what Macro do even more..
3) Code is more flexible
4) Code can have an error handler to stop crashing your app where macro breaks in between.
5)As far as I know Microsoft have stopped developing Macro further.
we will wait experts to reply to this thread
regards

Zameer Abdulla
 
A module is a container for Procedures and Functions written in VBA.
Your example:
Code:
Sub Quit()
Application.Quit
End Sub

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
This is what I understand (maybe I am repeating).
I can have a module to contain both codes such as the one you have quoted (PHV) or a function. So a module can contain both.

As I understand it is better to convert a macro into a module (function based), and best to convert a function to a subroutine.
most speed less speed least speed
Subroutine function macro


Is this the essence? Cheers
 
Can I ask one more question???
How do you run a module from code builder???

say a module is called quit with a code as:
sub quit()
application.quit
end sun

The easy way is to copy paste the application.quit code.

Assume that you are pressing a button on a form and on click you want to run the module quit. Is this what the module is supposed to be or do I make the wrong assumption/
Cheers
 
Greek Patriot said:
" ... function to a subroutine ... "

No. Subbroutines and Functions are "Procedures". Both are in modules (or even the SAME module). Subroutines do not return a value, Functions ALWAYS return a value. No other (internal) differences.





MichaelRed


 
Say you have coded the following:
Public Function myQuit()
Application.Quit
End Function
Then anywhere an expression may be build you can type:
=myQuit()

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
PHV you are really helpfull, appreciated. This worked.

Michael Red quote "Functions ALWAYS return a value"
Does this function return a value???
Public Function myQuit()
Application.Quit
End Function

Are you trying to confuse me more? I think a function always uses an equal sign ====================== that is the difference but they could perform the same calculations.
 
Does this function return a value?
YES, a Null value.
Why ?
Because the Function is not typed so it returns a Variant and a variant with no assignment holds a Null value.

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
OK guys since you agree I have to agree too. Although one think that readily pops to mind is, if a module is assigned to a command button using the expression builder on click =myquit() where is the result?????? Where is the Null value?? ok this is where I get confused. Propably I am looking at it from a different perspective which is probably wrong.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top