Solved

Declaration using Public

Posted on 1998-08-02
2
151 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Want Experts Exchange at your fingertips?

With Experts Exchange’s latest app release, you can now experience our most recent features, updates, and the same community interface while on-the-go. Download our latest app release at the Android or Apple stores today!

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…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
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…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses
Course of the Month6 days, 19 hours left to enroll

623 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