Solved

Declaration using Public

Posted on 1998-08-02
2
134 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
Comment Utility
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
Comment Utility
u have answered my question well, thanks
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

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…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
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…

772 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now