Download presentation
Presentation is loading. Please wait.
Published byPaula Campbell Modified over 8 years ago
1
Lecture 3 Visual Basic for Applications in Access 1 Rapid Application Development
2
2 Topics of this lecture l VBA and relationship to VB6 l The VBA IDE l Modules l Simple VBA programming using objects which are not data bound l Drop down lists, Combo Boxes and Option buttons l To what extent is VBA an Object Oriented language
3
3 Introduction to VBA 1/2 l VBA stands for Visual Basic for Applications l Many tasks cannot be implemented using the standard Forms, Queries, Reports and macros in Access ne.g. when you want a piece of code to be shared by several forms/reports l VBA is Microsoft's programming tool for MS Office users nnot only in Access, but also in other applications of the MS Office Suite l A version of VBA is implemented within Access nfor developing and executing VBA code nit does not require any other IDE (Integrated Development Environment) outside Access
4
4 Introduction to VBA 2/2 l Relationship to Visual Basic 6 nVBA is currently very similar to VB6 nshares many libraries, e.g. othe DAO (data Access Objects) oRDO (Remote Data Objects) oADO (ActiveX Data Objects) oother libraries of DLL's as well as 'built-in' VBA being a subset of VB6, ie most of the code and controls (and control properties) which you can use in VB6 are also implemented in VBA. About VBA in Access 2007
5
5 Modules and the VBA IDE l Code is written using the VBA IDE windows nVBA code is associated with to the currently selected form/report na free-standing module that can be shared by the forms and reports l To write code nIn the Design View, click on the Code icon on the Design ribbon nthen the VBA IDE window would appear
6
6 Adding controls and code to a form module 1/3 You can do the same things with controls and forms in Access as in Visual Basic 6, ie: l place controls on a form l code event procedures which are triggered when the event occurs l call procedures from general (shared) modules
7
7 Adding controls and code to a form module 2/3
8
8 Adding controls and code to a form module 3/3 l Create event handler via the button’s Property sheet
9
9 List boxes, Combo Boxes, Check Boxes and Option Groups (1/2) Combo Box List Box Check Box Option box
10
10 Using List boxes, Combo Boxes, Check Boxes and Option Groups (2/2) l Possible uses: ndisplay multiple entry data olook up table e.g. customer ID ndata validation oonly valid entries are displayed u e.g. YES/NO, checked/unchecked l How to add to a form nplace a control from the Toolbox onto the form nthe Wizard will pop-ups
11
11 An example: the Combo Box Wizard
12
12 Combo Box Properties Window l Tailoring a combo box using its Property sheet
13
13 The Object Metaphor in Access The concepts of objects, classes, object instances, properties and methods in Object Oriented languages l Examples: a database, a table, a form, command buttons l What is the object? nA programming concept that has evolved from odata types ofunctions othe combination of the two othe idea of re-using the code u modular programming u libraries
14
14 What is the object? na software component that encapsulates odata/properties ofunctions/behaviour/methods nThe Class otemplate in code, at the design time (a class module in VB) nAn object is an instant of a class oat runtime oexits in the computer memory oan object always has a state, the class doesn’t nThe objects of a class make a collection (in VB) oE.g. collection of all accounts of a bank
15
15 Visual Basic and OO (1/2) l VBA does not support inheritance (but VB.net does) nIn VBA: the behaviour of a class may not be modified to make a new sub-class l VB allows using and creating classes and objects nExamples of objects in VB oForm oany VB controls nClass Module in VB has: oproperties omethods l Use the VB IDE Object Browser (F2) to explore what objects are present in your project nSee next slide
16
16 Visual Basic and OO (2/2)
17
17 Summary l The Visual Basic for Applications in Access ncompared to VB6 nVB IDE l Using VBA in Access nclass modules nfree-standing modules l Use of controls in VBA for data displaying and input with validation l OO and VBA
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.