Copyandpaste code from the

Many programmers start their careers not so much by writing code from scratch but rather by using code that others have written and adapting it to their own needs. When that code is displayed onscreen, as in a Web page, the first step is to copy and paste the code into a module, where you select what you want to copy, copy it (press Ctrl+C), click in your module, and paste (press Ctrl+V).

Suppose you're browsing the Web, and you come across a sample procedure in a Web page. You don't want to retype the whole procedure into your own module, so you need to copy it. First, you need to select the whole procedure (and nothing but the procedure) by dragging the mouse pointer through the whole procedure — from the starting Sub or Function statement to the ending End Sub or End Function statement. After you select the code, press Ctrl+C or right-click anywhere in the selected text and choose Copy, as in Figure 3-8.

After you select and copy the code, just click anywhere in a standard module and then choose Paste. The exact code you selected will appear in your module.

You can find most of the code examples from this book at www.coolnerds. com/vba. You can copy and paste any code from that site into any module in your own database.

Figure 3-8:

Use sample VBA code from a Web page.

i ' New Page 1 - Microsoft Internet Explorer

EBB)

File Edit View Favorites Tools Help

Address | dg] http ; ff w w w ■ coolnerds ■ com/Access/SampleCode .htm

Custom lsOpen() Function

The IsOpen function below is similar to the IsLoadedQ function that comes with the sample Northwind database. To use it in your code, call it with the syntax IsOpenf/omWame) where formName is the name of the form you're testing, If the form is open in any view other than Design view, then IsOpen[] returns True, Otherwise, it returns False:

The IsOpen function below is similar to the IsLoadedQ function that comes with the sample Northwind database. To use it in your code, call it with the syntax IsOpenf/omWame) where formName is the name of the form you're testing, If the form is open in any view other than Design view, then IsOpen[] returns True, Otherwise, it returns False:

Function IsOpen(strFormName As String] As Boolean B Dim myObject As AccessObject

Set myObject - C u rrent Proj e c t. All Form s f s t r Fo rm N am e If myObject.IsLoaded Then HHlHHHHflHiH

If myObject, Current View <> acCurViewDesign Ther|j

Cut

Copy

Paste Select All Print

Google Search

c£| Copies the selection to the Clipboard.

0 0

Post a comment