What Is a Method

Methods are actions that can be taken on an object. They are really sub procedures or functions that are called to perform a particular action. You do not see the code behind sub procedures or functions when using existing Access objects, but they are there.

An example of a method you have already used is:

Debug.Print

The programmers who wrote Microsoft Access created a Debug object to allow you to interact with the Immediate Window, as you have already done to test your code. Somewhere in the source code for the Debug object is a sub procedure or function called Print that receives the message to print as a parameter and then has code for displaying the message in the Immediate Window. Because Microsoft does not give you the source code for Microsoft Access, you do not see this code—but it's there. This is also true for objects created by other third parties—a sub procedure or function is behind the method.

Let's look at an example of how you can see what methods are available for an object. In the code window in the VBE (Figure 3.5), you can type the object name followed by a period, just as you did before. You get a drop-down list that shows the available methods. Recall from the prior section, you can also use this feature to view the properties available for an object.

In the preceding example, you can see that the Recordset object has properties such as Name and NoMatch, but it also has various methods, such as MoveLast and MoveNext. You can tell whether the

Figure 3.5

item in the list is a property or method based on the icon displayed to the left. You might say the icon for methods looks like a brick in motion:

You might describe the icon differently, but the point is that this icon indicates that the item in the list is a method. Recall that the hand holding the card is the icon for the Properties window. Another way to see the methods and properties available for an object is using the Object Browser, as you will see later in the chapter.

0 0

Post a comment