Unformatted text preview:

Explore Objects and Collections Callahan Chapter 12 Introducing the Issues Application Startup form to identify the user selection is stored in a global Public variable named lngCurrentEmpID so any form report query procedure can detect who the user is Practice Time Quiz in which Module was the variable declared how does lngCurrentEmpID get assigned 1 Review Objects Properties Methods and Events Object Property attributes which define an object s appearance and behavior egs Enabled AllowEdits Name BackStyle TextAlign Method a combination of code and data that can be treated as a unit egs a form a textbox a form s recordset DoCmd Error an action that can be taken on or performed by an object egs SetFocus Requery OpenForm Event a state condition or occurrence on with an object egs Current AfterUpdate Click Telling Properties from Methods Statements involving properties will reference the property s value Me AllowEdits True If Forms frmProjects txtClientID Value 0050 Then Statements involving methods won t refer to a value Me Requery Forms frmProjects txtClientID SetFocus DoCmd GoToRecord acNewRec 2 Objects and Classes An object is created from a class Example the formal definition of an object that acts as the template blueprint from which an instance of an object is created defines an object s properties and methods a form is a type of object when Access creates a new form it creates it based on the Form Class each form has properties methods events a collection of sections a collection of controls as defined by the Form class Example Callahan 11 used a FileDialog object so user could point to the back end we had to set a reference to the Microsoft Office 12 Object Library in order to have the FileDialog Class available defined the file picker dialog box its properties and methods Understanding Objects and Collections Collection an object that contains a set of related objects generally contains objects of the same type examples AllForms collection Forms collection Controls collection contains all saved forms present in an Access database contains all currently open forms in an Access database contains all of the controls on a form or report used to enumerate individual controls count them set their properties example set the background color property of each control each collection is a zero based group of objects each collection has properties and methods including Count Add Remove 3 Try Out the Object Browser View an object s properties events methods any objects defined in the application and in any referenced libraries press F2 to launch Object Browser from within VB editor press F1 to view Help regarding the selected Module Class Member Object Libraries Class Libraries referenced in Issues mdb Access contains objects methods constants for application s user interface forms reports controls DoCmd object Screen object ADODB ActiveX Data Objects contains objects methods constants used to work directly with database files and the data they store Issues contains the Issues mdb application s forms reports modules their controls properties and procedures VBA contains VBA functions constants Error object egs IsNull MsgBox Date vbOK vbBlue Demo Object Browser Access Object Library AllForms Application ComboBox Constants DoCmd Form Forms VBA Object Library IIF search for it Constants ADODB Object Library Connection Recordset Issues Object Library Messages globals Microsoft Office 12 Object Library FileDialog 4 Using Bang and Dot in Object References bang dot used between an object and a method or property object method object property Examples used between a collection name and a member object of the collection collection object Me AllowEdits True Forms Contacts AllowEdits True rstContacts Refresh Me Filter City New York string within a string Summary collection object method collection object property Referring to Objects and Collections 3 ways to refer to an object within a collection by index number members of a collection are numbered beginning with 0 useful when looping through a collection in VB code caution elements of collection can change index numbers will too Forms 1 Forms 2 by its name as a string Forms 0 Forms Contacts Forms strFormName Forms Contacts Controls txtWriterID Forms Contacts txtWriterID by its name using bang notation Forms Contacts Forms Contacts Controls txtWriterID Forms Contacts txtWriterID each bang style reference is translated into the equivalent parentheses andquotes style reference 5 Guided Tour In your Issues mdb file open only the Issues form then do each of the following in the Immediate window forms count 1 forms 0 name Issues forms Issues activecontrol name Title forms Issues activecontrol name Title forms Issues activecontrol value Problem with product name forms issues controls count remember this answer for the quiz forms issues controls 0 value 1 forms issues controls 2 value Problem with product name forms issues comments form comment Checked with our general counsel We must fix this problem before releasing the product Using the For Each Statement with a Collection For Each Next used to perform the same action on each object in a collection sets up a loop that executes the same set of statements repeatedly Placed this code in the Miscellaneous module Sub ChangeLabelColor strFormName As String lngColorCode As Long change the color of labels on the specified form Dim ctl As Control For Each ctl In Forms strFormName Controls If TypeOf ctl Is Label Then ctl ForeColor lngColorCode End If Next ctl object collection End Sub changelabelcolor issues vbBlue changelabelcolor issues vbBlack 6 Using a Multiple Selection List Box MultiSelect property controls whether users can make multiple selections in a list box None Default users can select multiple items by clicking Extended users can select only a single item Simple used here users can select multiple items by holding Shift or Ctrl use VBA code to determine which rows are selected and process them ListCount property returns the number of rows in the list box forms reassigner issuelist multiselect 1 forms reassigner issuelist listcount 4 Using a Multiple Selection List Box ItemData property returns data in the bound column for a specified row in a list box or combo box ItemData 0 points ItemData 1 points ItemData 2 points ItemData 3 points to to to to the the the the first row displayed second row displayed third row displayed fourth row displayed 0 1 2 3 7 Using a Multiple Selection List Box


View Full Document

SCC CIS 217AM - Callahan Chapter 12

Loading Unlocking...
Login

Join to view Callahan Chapter 12 and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Callahan Chapter 12 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?