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