Solved

Declaration using Public

Posted on 1998-08-02
2
140 Views
Last Modified: 2010-05-03
May i know what are the differences between the
Public db as Database &
Dim db as Database?

When I am using the Public db as Database, the compilation error of UserDefined type not specified is given..

Please give me advice when should i use the Public to declare variable and how?

Waiting for ur reply, thanks

SRQ
0
Comment
Question by:SRQ
2 Comments
 
LVL 6

Accepted Solution

by:
clifABB earned 100 total points
ID: 1467506
With the error you have received, it looks like you haven't added a reference to the Data Access Object (DAO).
In VB's main screen, select menu option Project/References.  From the dialog box scroll down till you get to the DAO objects.  Unless you have a reason to select a lower version number, select the DAO with the highest object number.

It seems MS is a pain in the behind on this.  Most apps developed with VB will use the DAO and yet the reference to it isn't defaulted.

As far as advice on using Public as opposed to Private.  You should try your hardest to avoid using public variables.  Public variables are harder to debug.

There are times when you do want a Public variable (a database object is a good example) usually this will be a variable which will not change in the life of the app.  Most variables you definitely do not want to be public (a loop counter is a good example).  Many a time I have wanted to kick a programmer who made a loop variable public and then the app ended up going through two loops at the same time in different parts of the app.
0
 

Author Comment

by:SRQ
ID: 1467507
u have answered my question well, thanks
0

Featured Post

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question