Presentation is loading. Please wait.

Presentation is loading. Please wait.

Access VBA Programming for Beginners - Class 1 - by Patrick Lasu

Similar presentations


Presentation on theme: "Access VBA Programming for Beginners - Class 1 - by Patrick Lasu"— Presentation transcript:

1 Access VBA Programming for Beginners - Class 1 - by Patrick Lasu p_lasu@lycos.com

2 Class 1 - Overview What is VBA? What is VBA? History of VBA History of VBA Event-Driven Programming Event-Driven Programming Helpful Hints Helpful Hints Code Window Code Window Help in VBA Help in VBA Subs and Functions Subs and Functions Variables and Constants Variables and Constants

3 What is VBA? VBA = Visual Basic for Applications VBA = Visual Basic for Applications Visual Basic is a stand-alone programming software that is event-driven Visual Basic is a stand-alone programming software that is event-driven VB for Applications = Visual Basic that is “customized” to work with Access, Excel, Word, etc. VB for Applications = Visual Basic that is “customized” to work with Access, Excel, Word, etc. –Excel has Sheet objects –Word has Document objects –Access has Data objects

4 Brief History Visual Basic for Applications (VBA) is derived from Visual Basic (VB) Visual Basic for Applications (VBA) is derived from Visual Basic (VB) –VBA was fully integrated into Office –97 except Outlook –Prior to that, there were Macros Before VB, there was QBasic (Microsoft Products) Before VB, there was QBasic (Microsoft Products) –Based on BASIC (Beginners All-purpose Symbolic Instruction Code) programming language

5 Brief History Languages based on BASIC got a bad rap because: Languages based on BASIC got a bad rap because: –They were considered slow –Need a software platform to run

6 Brief History CPU Windows VB Software Platform for VB

7 Brief History CPU Windows Access VBA Software Platform for VBA

8 Event-Driven Programming What is it? What is it? –Code does not execute until an event is happening »Analogy: You answer the phone when it rings instead of picking up the receiver every 2 seconds to find out if somebody is calling. –Program is Form-centric »Code uses forms, which breaks up code into smaller portions, and gives the user flexibility when entering data.

9 Helpful Hints There are at least 3 ways of accomplishing the same task when coding There are at least 3 ways of accomplishing the same task when coding –Good Code = It works –Bad Code = It does not work Strive to make your code as short as possible Strive to make your code as short as possible –It saves time when typing code –Runs faster –Easier to debug Save Often (Ctrl + S) Save Often (Ctrl + S)

10 Variables and Constants A variable is a storage for a value that can change during code execution A variable is a storage for a value that can change during code execution –Answering Yes or No A constant is a storage for a value that does not change during code execution A constant is a storage for a value that does not change during code execution –3.1415, vbYes, vbRed –Can be changed manually »Going from 365 days to 360 days when calculating interest

11 Variables and Constants There are several Data Types for Variables and Constants for efficiency There are several Data Types for Variables and Constants for efficiency –String = Stores Text – “Patrick”, “123 Main St” –Number = Stores Numbers - “1, 2, 3,...”, “3.14” –Boolean = Stores True/False –Date = Stores Date –Currency = Currency format – “Dollar, Yen” –Variant = Stores Anything And there are many more!!!! And there are many more!!!!

12 Variables and Constants We will work mostly with (for starters): We will work mostly with (for starters): –Strings –Integers (whole numbers, no decimals) –Boolean –Variant

13 Variables and Constants Naming convention for Variables: Naming convention for Variables: –Strings – Starts with “str” »strFirstName –Integers – Starts with “int” »intCount –Boolean – Starts with “bln”, “bol”, “bool” »boolExit –Variant – Starts with “var” »varAnyValue

14 Variables and Constants A variable needs to be declared A variable needs to be declared Syntax: Dim variablename [As type] –Dim = Dimension (make space for it) –variablename = Ex: strFirstName –[As type] = Optional, Ex: As String Dim strFirstName As String

15 Variables and Constants Naming convention for Constants Naming convention for Constants –We’ll do it in next class!!!! –We’ll also talk about Public and Private variables and scope/visibility –Why not making all variables Variants –And much more…

16 Review It works!!! = Good Code It works!!! = Good Code –Code is short and sweet = Even better… There are at least 3 different ways of coding There are at least 3 different ways of coding Save Often Save Often Use the Help files Use the Help files


Download ppt "Access VBA Programming for Beginners - Class 1 - by Patrick Lasu"

Similar presentations


Ads by Google