The mechanics of Access programming

P

Pete Davis

First a quick bit about my background. I'm programmer, but I normally work
with C++, C#, and so forth. I haven't done much with Visual Basic nor Visual
Basic for Applications and I'm a bit confused on the mechanics of it.

First of all, I've got an access form with a button on it. When the button
is pressed, I want to display the File/Open dialog.

I got this code: http://www.mvps.org/access/api/api0001.htm

and I'm a bit confused on where to go from here.

I went into "View Code" from access and copied the code in.

The first issue I get is about the Type definition. Upong trying to compile
I get: Cannot define a Public user-defined type within an object module.
Where does this go?

The second issue is with the Global Const definitons which give me the
error: Constants, fixed-length strings, arrays, user-defined types, and
Declare statements not allowed as Public members of object modules. Again,
where does this code go?

This would give me a good start. Thanks.

Pete
 
A

Allen Browne

Pete, select the Modules tab of the database window.
Click New to create a new module.
Paste the code form the website in here.

That's a standard module, and you should be able to call the function from
anywhere else (e.g. the module of a form).

--
Allen Browne - Microsoft MVP. Perth, Western Australia.

Reply to group, rather than allenbrowne at mvps dot org.

news:[email protected]...
 
L

Larry Linson

There is an example of using that API code in the imaging examples at
http://accdevel.tripod.com. Perhaps that will help. The api0001 code itself,
though, has an example of how to call it. The actual call will be in the
Click event of your Command Button, if that was not clear.

Larry Linson
Microsoft Access MVP
 
J

Jim Carlock

If you're creating classes within VBA, the classes behave alot like
C++ classes. A module is kind of a global item for that particular
Access application. Typically you declare constants, functions,
subroutines, et al within modules. Modules are NOT class-like.

If the constant is declared as Public within the module, it's visible
through out the Access application. If the variable or constant is
declared as Private, it's only visible within the module.

Variables are typically declared with the Dim statement within
subroutines and functions. These variables can only be declared
with the Dim keyword and they are local variables to the routine
they are called within. These local variables will override and take
precedence within the routine. Meaning if a variable is declared:

Dim s As String

within a subroutine, and it's also declared outside the subroutine,
any use of s within the subroutine will apply to the localized variable
unless the two variables are of two different types. I wouldn't trust
anything I'm saying in this respect here, because, the issues are kind
of hazy, and I never personally trust such issues when I'm
programming.

I typically declare global variables in a Hungarian fashion with a
prefix of "g". If it's a module wide private variable, it'll have an "m"
prefix. If it's a localized variable, they just get the Hungarian prefix,
"i" for Long (32bit), str or "s" for Strings, "r" for Single types.

Some folks use Integers, but I've digressed from the Integer
altogether. Integers are 16-bit numerics, and Boolean types translate
into such. Typically Boolean variables are designated as True or
False. False is 0, True is -1. If testing for true things though, just
use syntax such as If i Then... assuming i is either a long or integer.
Using the:

If i Then

means that if i is non-zero execute the following. The following though
will test false if i = 3,

If i = True Then

True literally translates to -1 when compared with a numeric value. A
numeric value that <> 0 figuratively translates to True when tested on
a line by itself.

Window addresses, hWnd, handles are almost always declared as
Long variables. Long variables always are 32-bit, unless you are
programming in .Net stuff.

Hope that helps some.

--
Jim Carlock
http://www.microcosmotalk.com/
Post replies to the newsgroup.


First a quick bit about my background. I'm programmer, but I normally work
with C++, C#, and so forth. I haven't done much with Visual Basic nor Visual
Basic for Applications and I'm a bit confused on the mechanics of it.

First of all, I've got an access form with a button on it. When the button
is pressed, I want to display the File/Open dialog.

I got this code: http://www.mvps.org/access/api/api0001.htm

and I'm a bit confused on where to go from here.

I went into "View Code" from access and copied the code in.

The first issue I get is about the Type definition. Upong trying to compile
I get: Cannot define a Public user-defined type within an object module.
Where does this go?

The second issue is with the Global Const definitons which give me the
error: Constants, fixed-length strings, arrays, user-defined types, and
Declare statements not allowed as Public members of object modules. Again,
where does this code go?

This would give me a good start. Thanks.

Pete
 

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