By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,154 Members | 1,024 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,154 IT Pros & Developers. It's quick & easy.

calling a function

P: n/a
Hi (again) ;-)

I'm still very much at the bottom of a steep learning curve with VB, so
any and all help is always appreciated.

I've found some code to generate the user names who have logged onto the
file in question and from what I've been reading it will do what I
need. However, what is eluding me is the "calling" it bit. If anyone
can put into simple terms what is needed & general principles I would be
really grateful.

Do you need to create a form that is populated by the function? Have or
am I totally missing the plot?

Stinky Pete ;-)
Feb 13 '07 #1
Share this Question
Share on Google+
5 Replies


P: n/a
Stinky Pete wrote:
Hi (again) ;-)

I'm still very much at the bottom of a steep learning curve with VB, so
any and all help is always appreciated.

I've found some code to generate the user names who have logged onto the
file in question and from what I've been reading it will do what I
need. However, what is eluding me is the "calling" it bit. If anyone
can put into simple terms what is needed & general principles I would be
really grateful.
Do you need to create a form that is populated by the function? Have or
am I totally missing the plot?

Stinky Pete ;-)
A form can be bound (table/query in recordsource) or unbound (not
associated with table/query).

There are events that are executed; Open, Current, BeforeUpdate, etc.
Events are where you'd put your code. You need to determine which event
would be best when calling your code/macros.

You can click on the events tab, move to a row, and press F1 to get help
on the property to see what it does.

The OnCurrent event fires for each record you move to. If unbound, it
fires after the open/load events. Maybe that's where you need to call
your code.
Feb 13 '07 #2

P: n/a
On Feb 14, 12:55 am, salad <o...@vinegar.comwrote:
Stinky Pete wrote:
Hi (again) ;-)
I'm still very much at the bottom of a steep learning curve with VB, so
any and all help is always appreciated.
I've found some code to generate the user names who have logged onto the
file in question and from what I've been reading it will do what I
need. However, what is eluding me is the "calling" it bit. If anyone
can put into simple terms what is needed & general principles I would be
really grateful.
Do you need to create a form that is populated by the function? Have or
am I totally missing the plot?
Stinky Pete ;-)

A form can be bound (table/query in recordsource) or unbound (not
associated with table/query).

There are events that are executed; Open, Current, BeforeUpdate, etc.
Events are where you'd put your code. You need to determine which event
would be best when calling your code/macros.

You can click on the events tab, move to a row, and press F1 to get help
on the property to see what it does.

The OnCurrent event fires for each record you move to. If unbound, it
fires after the open/load events. Maybe that's where you need to call
your code.
Thanx for the info. It's helped and I will keep looking and playing
to understand this better. As mentioned, this type of thing is really
new to me so there may be a few more posts ;-)

Stinky Pete ;-)

Feb 13 '07 #3

P: n/a
Stinky Pete wrote:
On Feb 14, 12:55 am, salad <o...@vinegar.comwrote:
>>Stinky Pete wrote:
>>>Hi (again) ;-)
>>>I'm still very much at the bottom of a steep learning curve with VB, so
any and all help is always appreciated.
>>>I've found some code to generate the user names who have logged onto the
file in question and from what I've been reading it will do what I
need. However, what is eluding me is the "calling" it bit. If anyone
can put into simple terms what is needed & general principles I would be
really grateful.
Do you need to create a form that is populated by the function? Have or
am I totally missing the plot?
>>>Stinky Pete ;-)

A form can be bound (table/query in recordsource) or unbound (not
associated with table/query).

There are events that are executed; Open, Current, BeforeUpdate, etc.
Events are where you'd put your code. You need to determine which event
would be best when calling your code/macros.

You can click on the events tab, move to a row, and press F1 to get help
on the property to see what it does.

The OnCurrent event fires for each record you move to. If unbound, it
fires after the open/load events. Maybe that's where you need to call
your code.


Thanx for the info. It's helped and I will keep looking and playing
to understand this better. As mentioned, this type of thing is really
new to me so there may be a few more posts ;-)

Stinky Pete ;-)
Depending on your version of Access you might want to consider a book
like Microsoft Step By Step for the version. You won't learn much
unless you do the exercises. It's a good book for when you are starting
to work with coding in Access.
Feb 14 '07 #4

P: n/a
I believe there's even a Step by Step book for Microsoft Access VBA, not
just the end-user book. I used an early (Access 2.0) edition to teach a
class for Paradox DB users moving to Access 2.0 and I've had feedback that
current editions of the end-user book is very good for self-study. I haven't
had occasion to use or review the Step by Step book for Microsoft Access
VBA.

Larry Linson
Microsoft Access MVP
"salad" <oi*@vinegar.comwrote in message
news:Yv*****************@newsread4.news.pas.earthl ink.net...
Stinky Pete wrote:
>On Feb 14, 12:55 am, salad <o...@vinegar.comwrote:
>>>Stinky Pete wrote:

Hi (again) ;-)

I'm still very much at the bottom of a steep learning curve with VB, so
any and all help is always appreciated.

I've found some code to generate the user names who have logged onto the
file in question and from what I've been reading it will do what I
need. However, what is eluding me is the "calling" it bit. If anyone
can put into simple terms what is needed & general principles I would be
really grateful.
Do you need to create a form that is populated by the function? Have or
am I totally missing the plot?

Stinky Pete ;-)

A form can be bound (table/query in recordsource) or unbound (not
associated with table/query).

There are events that are executed; Open, Current, BeforeUpdate, etc.
Events are where you'd put your code. You need to determine which event
would be best when calling your code/macros.

You can click on the events tab, move to a row, and press F1 to get help
on the property to see what it does.

The OnCurrent event fires for each record you move to. If unbound, it
fires after the open/load events. Maybe that's where you need to call
your code.


Thanx for the info. It's helped and I will keep looking and playing
to understand this better. As mentioned, this type of thing is really
new to me so there may be a few more posts ;-)

Stinky Pete ;-)
Depending on your version of Access you might want to consider a book like
Microsoft Step By Step for the version. You won't learn much unless you
do the exercises. It's a good book for when you are starting to work with
coding in Access.

Feb 15 '07 #5

P: n/a
On Feb 13, 8:55 am, salad <o...@vinegar.comwrote:
Stinky Pete wrote:
Hi (again) ;-)
I'm still very much at the bottom of a steep learning curve with VB, so
any and all help is always appreciated.
I've found some code to generate the user names who have logged onto the
file in question and from what I've been reading it will do what I
need. However, what is eluding me is the "calling" it bit. If anyone
can put into simple terms what is needed & general principles I would be
really grateful.
Do you need to create a form that is populated by the function? Have or
am I totally missing the plot?
Stinky Pete ;-)

A form can be bound (table/query in recordsource) or unbound (not
associated with table/query).

There are events that are executed; Open, Current, BeforeUpdate, etc.
Events are where you'd put your code. You need to determine which event
would be best when calling your code/macros.

You can click on the events tab, move to a row, and press F1 to get help
on the property to see what it does.

The OnCurrent event fires for each record you move to. If unbound, it
fires after the open/load events. Maybe that's where you need to call
your code.
As a relative newbie to this world, I still remember the confusion.
There are two types of basic calls.

Salad describes the first one where you use the event on the form to
"call" the code for that event. This is usually where people start
using VBA... after they've done a few macros and find that macros
can't do something.

The second type is when you've called VBA using the event on a form,
but... then you want to call an _additional_ code from your event
code. You usually do this because you want to use the same code in
multiple forms without having to copy it over and over again.

Basically, there are "sub"s and "function"s that you can "call". A
sub is basically code that executes and is done. A function looks
just like a sub... only you can send data to it, and receive data back
as an answer.

You can save these in the code for the form or report you're working
on. Or, you can save them for common use by multiple forms or
reports. To do this, save them in a module.

To "call" a sub or a function, you simply type

call functionname(firstvariable,secondvariable)
' or
call subname

within your code. That will cause the sub or function to execute.

If you have a function that returns a result, then you can also "call"
it by using it as a variable. Say you wrote a function called
"PullLastUser" that looked up the last user of an application. You
could make a button that had this code on the "OnClick" event...

msgbox "The last person to use this database was " &
PullLastUser("DatabaseName")

You could get fancy and let the user pick from a list of applications
in a dropdown. This would look more like...

strApplicationName = me!cmbApplicationName
strLastUser = PullLastUser(strApplicationName)

Access and VBA have some help files if you search for "call
statement", "sub statement" and "function statement". These might
help. But, they're short and cryptic. Personally, I learned a ton
from using sample code and reading this group. But, nothing really
clicked until I took a few classes from UMSL. Those were awesome, but
my company paid.

So, if Salad and Larry recommend the Step by Step books, then I'd jump
on them. Those guys know what they're talking about.

Jon

Feb 15 '07 #6

This discussion thread is closed

Replies have been disabled for this discussion.