Function Modules vs Sub Modules

L

Larry

If Functions are used to return a value and Subs perform event based actions.
How should I run a module that doesn't return a value and isn't necessary
event based?

I periodically import a csv file. Once, after each import, I want to run a
Module that opens the table to cycle through the records to do a lot of field
manipulation and update each record and end up with a cleaned up table. This
is just to prep the file for various other uses.

It would seem I should be able to execute it from a macro, but the Runcode
in macros seems to want only a Function Module to run.

Should I just create a Function that Calls the Sub Module and ignore that
the function wants to return a value?
Or, should I create a dummy form and use the OnLoad event to run the code I
need?

But both of these seem like a round about way to get there since I don't
want to view the data in a for and don't want a value returned.

What's the correct way to run this kind of process?
 
A

Allen Browne

Just use a function.

Functions don't have to return a value, i.e. you don't have to assign
anything.

In most cases, you can dream up something a function should return, e.g. the
number of records appended, or a success/fail flag.

It's a question of style, but I never create Subs (other than the built-in
ones for event procedures.)
 
M

Magius96

See, here's a wonderful example of how every persons style of coding is
different. :)

My general rule of thumb is to use functions for anything that will return a
value, and a subroutine for anything that does not. While it's true that
subroutines are used for even based procedures, it's not the rule.
Subroutines are only event based if they are setup to be event based. For
instance, clicking a button will call the subroutine defined in the button to
handle that event. If a subroutine is not defined on any controls to handle
an event, then techincally it is not event based.
 
L

Larry

Great! Thanks Allen! And returning some kind of success flag would be most
appropriate.
--
Regards
Larry


Allen Browne said:
Just use a function.

Functions don't have to return a value, i.e. you don't have to assign
anything.

In most cases, you can dream up something a function should return, e.g. the
number of records appended, or a success/fail flag.

It's a question of style, but I never create Subs (other than the built-in
ones for event procedures.)
 
L

Larry

Thanks! It seemed like it didn't matter but I wanted to make sure there
wasn't some problem or disadvantage I was going to find later.
 

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

Similar Threads


Top