Solved

Declaration using Public

Posted on 1998-08-02
2
137 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
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 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…

863 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

22 Experts available now in Live!

Get 1:1 Help Now