1 / 16

Access VBA Programming for Beginners - Class 1 -

Access VBA Programming for Beginners - Class 1 -. by Patrick Lasu p_lasu@lycos.com. Class 1 - Overview. What is VBA? History of VBA Event-Driven Programming Helpful Hints Code Window Help in VBA Subs and Functions Variables and Constants. What is VBA?.

wang-avery
Download Presentation

Access VBA Programming for Beginners - Class 1 -

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


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

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

  3. What is VBA? • VBA = Visual Basic for Applications • 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. • 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) • VBA was fully integrated into Office –97 except Outlook • Prior to that, there were Macros • 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: • They were considered slow • Need a software platform to run

  6. Brief History Software Platform for VB VB Windows CPU

  7. Brief History Software Platform for VBA VBA Access Windows CPU

  8. Event-Driven Programming • 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 • Good Code = It works • Bad Code = It does not work • Strive to make your code as short as possible • It saves time when typing code • Runs faster • Easier to debug • Save Often (Ctrl + S)

  10. Variables and Constants • 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 • 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 • 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!!!!

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

  13. Variables and Constants • 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 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 • 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 • Code is short and sweet = Even better… • There are at least 3 different ways of coding • Save Often • Use the Help files

More Related