By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
431,983 Members | 1,717 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 431,983 IT Pros & Developers. It's quick & easy.

Setting Data Types

P: 31
I am a veteran of Access, but new to VBA. Why is it neccessary to to set data types, and do you need to do it always? I feel that if the info is already in a table or query, that it is already defined.

Thank you in advance.
Sep 9 '08 #1
Share this Question
Share on Google+
2 Replies


Expert Mod 2.5K+
P: 2,545
Hi, and Welcome to Bytes!

It's possible to write books on data types, so in this answer I will just skim the surface a bit.

VBA is a programming environment which provides facilities not generally provided by the SQL-based database itself (sequential processing instead of set processing, loop processing, asynchoronous event generation and response for example).

VBA and the database engine are entirely separate, albeit complementary, systems, and work in entirely different ways. That the database engine has data stored in tables with particular types is really not known at all to VBA. Although the type of a database field can be determined by VBA, through querying the properties of the table definition concerned, this has no bearing on what you do with VBA.

Programming languages work by assigning space for variables in memory then processing these variables using a sequence of assignment and conditional statements. Unlike database fields, which persist in value after use through being stored in a physical medium such as a disk file, variables are volatile - created for the current code module and destroyed after use.

The use of types defines the range of values variables will accept, and the range of operations that the variable can participate in. Assigning types explicitly is a way of ensuring that programmers make fewer mistakes. Untyped variables (which are called Variants in VBA) have no protection whatsoever from incorrect usage - attempts to add boolean values as numbers, for example.

Languages which enforce the use of data types strictly are known as strongly-typed. VBA is not a strongly-typed language, because it does not of itself enforce data typing, although a compiler directive called Option Explicit will ensure that no variable can be used unless it is defined first (it still does not need to have an assigned type even so).

Typed variables are also much easier to understand when reading code, and are a useful aid for documenting what a routine does.

That's about all I can tell you at present without invoking texts on Software Engineering.

-Stewart
Sep 9 '08 #2

P: 31
Thank you very much for the quick and thorough reply. You really explained it well. You got me the answer that my Dummies book did not(though that has been helpful as well)
Sep 10 '08 #3

Post your reply

Sign in to post your reply or Sign up for a free account.