Object reference syntax, where can I find it defined?

T

tinnews

I am a died in the wool Java/C/C++ and some time Python programmer but
I occasionally have to dabble in Access and VB. Every time I do this
I get totally confused (and frustrated) by the syntax for object
references in VB.

Can anyone point me at a good "programmer's reference" type guide to
the basic syntax of object references in Access/VB please.

I'm currently trying to run a function (that I have written) from the
AutoExec macro so the function gets run at startup. I'm messing around
with:-

Modules.Module1.startupCheck()
Modules![Module1]!startupCheck()

and all points south to very little effect.

I'd much rather find some documentation that tells me how to do it
rather than guess and get there by trial and error.
 
R

Rick Brandt

I am a died in the wool Java/C/C++ and some time Python programmer but
I occasionally have to dabble in Access and VB. Every time I do this
I get totally confused (and frustrated) by the syntax for object
references in VB.

Can anyone point me at a good "programmer's reference" type guide to
the basic syntax of object references in Access/VB please.

I'm currently trying to run a function (that I have written) from the
AutoExec macro so the function gets run at startup. I'm messing
around with:-

Modules.Module1.startupCheck()
Modules![Module1]!startupCheck()

and all points south to very little effect.

I'd much rather find some documentation that tells me how to do it
rather than guess and get there by trial and error.

If there is a clear, concise reference document it will be found on the web and
it won't be written by anyone who works for Microsoft :)

It's really not that convoluted. Generally speaking...

foo!bar
....indicates that foo is a collection and bar is a member of that collection
and...

foo.bar
....indicates that foo is an object that has methods and or properties and that
bar is one of those methods or properties.

Where it gets confusing is that many Access objects have a default collection.
So...

foo!bar
....might not mean that foo is a collection, but it could be an object that has a
default collection and bar is a member of that. A common example is a form.
FormName!ControlName can be used to refer to a control on a form, but that is
really shorthand for...

FormName.Controls!ControlName

....because the Controls collection is the default collection for a form or
report.

To further complicate things Access will take all of the controls in the
Controls collection and will also make them into Properties of the form or
report object. That is why FormName.ControlName also works as a reference to a
control on a form. In these cases either syntax works and it comes down to
individual preference.

In your case if module is a standard module (not a class module) then you can
just refer to your sub or function by name directly. No reference to the
Modules collection or the specific module name is required. Just use...

startupCheck()
 
T

tinnews

Rick Brandt said:
I am a died in the wool Java/C/C++ and some time Python programmer but
I occasionally have to dabble in Access and VB. Every time I do this
I get totally confused (and frustrated) by the syntax for object
references in VB.

Can anyone point me at a good "programmer's reference" type guide to
the basic syntax of object references in Access/VB please.

I'm currently trying to run a function (that I have written) from the
AutoExec macro so the function gets run at startup. I'm messing
around with:-

Modules.Module1.startupCheck()
Modules![Module1]!startupCheck()

and all points south to very little effect.

I'd much rather find some documentation that tells me how to do it
rather than guess and get there by trial and error.

If there is a clear, concise reference document it will be found on the web and
it won't be written by anyone who works for Microsoft :)

It's really not that convoluted. Generally speaking...

foo!bar
...indicates that foo is a collection and bar is a member of that collection
and...

foo.bar
...indicates that foo is an object that has methods and or properties and that
bar is one of those methods or properties.

Where it gets confusing is that many Access objects have a default collection.
So...

foo!bar
...might not mean that foo is a collection, but it could be an object that has a
default collection and bar is a member of that. A common example is a form.
FormName!ControlName can be used to refer to a control on a form, but that is
really shorthand for...

FormName.Controls!ControlName

...because the Controls collection is the default collection for a form or
report.

To further complicate things Access will take all of the controls in the
Controls collection and will also make them into Properties of the form or
report object. That is why FormName.ControlName also works as a reference to a
control on a form. In these cases either syntax works and it comes down to
individual preference.
Not that convoluted! :)

In your case if module is a standard module (not a class module) then you can
just refer to your sub or function by name directly. No reference to the
Modules collection or the specific module name is required. Just use...

startupCheck()
Absolutely right, thanks. What confused me was the error message I
got when I forgot the () at the end indicating it was a function. The
error message wittered on about [Module]![ModuleName]![object].
 
T

tinnews

raskew via AccessMonster.com said:
Hi -

Drop the Modules.Module1 (assuming Module1 is a standard module)

The call should be: startupCheck
It should be startupCheck(), just startupCheck gives the error that
confused me to start with:-
...
...
For example Forms![Products]![UnitsInStock]

.... and anyway why *can't* I specify the full specification of where
startupCheck() is?
Bob

I am a died in the wool Java/C/C++ and some time Python programmer but
I occasionally have to dabble in Access and VB. Every time I do this
I get totally confused (and frustrated) by the syntax for object
references in VB.

Can anyone point me at a good "programmer's reference" type guide to
the basic syntax of object references in Access/VB please.

I'm currently trying to run a function (that I have written) from the
AutoExec macro so the function gets run at startup. I'm messing around
with:-

Modules.Module1.startupCheck()
Modules![Module1]!startupCheck()

and all points south to very little effect.

I'd much rather find some documentation that tells me how to do it
rather than guess and get there by trial and error.
 
B

boblarson

Because VBA doesn't work that way with its modules and procedures. You just
have to call it, but within the scope of the procedure. You can't call a
PRIVATE procedure outside of the scope of within the module it is located.
--
Bob Larson
Access World Forums Super Moderator
Utter Access VIP
Tutorials at http://www.btabdevelopment.com
If my post was helpful to you, please rate the post.
__________________________________


raskew via AccessMonster.com said:
Hi -

Drop the Modules.Module1 (assuming Module1 is a standard module)

The call should be: startupCheck
It should be startupCheck(), just startupCheck gives the error that
confused me to start with:-
...
...
For example Forms![Products]![UnitsInStock]

.... and anyway why *can't* I specify the full specification of where
startupCheck() is?
Bob

I am a died in the wool Java/C/C++ and some time Python programmer but
I occasionally have to dabble in Access and VB. Every time I do this
I get totally confused (and frustrated) by the syntax for object
references in VB.

Can anyone point me at a good "programmer's reference" type guide to
the basic syntax of object references in Access/VB please.

I'm currently trying to run a function (that I have written) from the
AutoExec macro so the function gets run at startup. I'm messing around
with:-

Modules.Module1.startupCheck()
Modules![Module1]!startupCheck()

and all points south to very little effect.

I'd much rather find some documentation that tells me how to do it
rather than guess and get there by trial and error.
 
T

tinnews

boblarson said:
Because VBA doesn't work that way with its modules and procedures. You just
have to call it, but within the scope of the procedure. You can't call a
PRIVATE procedure outside of the scope of within the module it is located.

OK, not very orthogonal though is it! :)
 

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

Top