Online Book Reader

Home Category

Access Cookbook - Ken Getz [265]

By Root 1972 0
avarGroups( ))

ExitHere:

acbPMGetGroups = intCount

On Error Resume Next

DDETerminate lngChannel

Err.Clear

Exit Function

HandleErr:

MsgBox Err.Number & ": " & Err.Description, , "acbGetProgmanItems"

Resume ExitHere

End Function

To call this function from your own code, use code like this:

Dim avarGroups( ) as Variant

Dim intCount as Integer

intCount = acbPMGetGroups(avarGroups( ))

' If you want the list sorted, call acbSortArray, in basSortArray.

acbSortArray avarGroups( )

To retrieve a list of items within a selected group, use the acbPMGetItems function, which works almost exactly as acbPMGetGroups does. This time, however, pass in a group name along with the dynamic array to be filled in; the function uses the group name as the topic, instead of PROGMAN (see Table 12-5). It calls the CopyToArray function to move the items into the dynamic array. You generally won't sort the array, however, unless you store the first item; this first item returns information about the group window itself. The rest of the rows contain information about the individual items. To use acbPMGetItems, you might use code like this:

Dim avarGroups( ) as Variant

Dim avarItems( ) as Variant

Dim intCount as Integer

intCount = acbPMGetGroups(avarGroups( ))

intCount = acbPMGetItems(avarGroups(0), avarItems( ))

' List all the item information for the specified group.

For intI = 0 To intCount - 1

Debug.Print avarItems(intI)

Next intI

Executing tasks


The Windows shell includes a command-string interface, which you can access via DDE, that allows you to execute tasks involving groups and items within those groups. Table 12-6 lists the functions addressed in this solution. Other commands are available (they're documented in the Windows SDK documentation), but they're not as useful for Access programmers.

Table 12-6. DDEExecute commands for the Windows shell

Function

Parameters

Comments

AddItem

See Table 12-7

Uses CreateGroup first to select the group.

CreateGroup

GroupName[, GroupPath]

Selects the group if it exists; otherwise, creates it.

DeleteGroup

GroupName

DeleteItem

ItemName

Uses CreateGroup first to select the group.

ShowGroup

GroupName, ShowCommand

See Table 12-8 for ShowCommand values.

In each case, you use the Access DDEExecute procedure to communicate with the shell. You must construct a string containing the function name, parentheses, and any arguments for the function. For example, to create a group from within Access, you can use code like this:

Dim intChannel as Integer

intChannel = DDEInitiate("PROGMAN", "PROGMAN")

DDEExecute intChannel, "[CreateGroup(My Group, MYGROUP.GRP)]"

The command string must be surrounded by square bracket delimiters ([]). Luckily, the Windows shell is far more relaxed about the use of embedded quotes than almost any other DDE-enabled application. For example, WinFax Pro's implementation of DDE requires quotes embedded in command strings you send to it; the Windows shell accepts embedded quotes but doesn't require them.

Some functions, such as AddItem, allow quite a few parameters, almost all of which can be left blank (see Table 12-7). To use the AddItem command to add a new item, you must first select a group in which to add the item. To do this, use the CreateGroup command, which creates a group if necessary or selects it if it already exists. The only required AddItem parameter is the command line. Note that both X- and Y-coordinates are necessary if you choose to specify coordinates for the icon. For example, to create a new icon to run C:\EDIT\MYEDIT.EXE with the description My Editor minimized in the My New Group group, use code like this (you'd normally include error-handling code, too):

Dim intChan As Integer

intChan = DDEInitiate("PROGMAN", "PROGMAN")

' First select the group (or create it).

DDEExecute intChan, "[CreateGroup(My New Group)]"

' Use commas to delimit parameters (even missing ones).

DDEExecute intChan, "[AddItem(C:\EDIT\MYEDIT,My Editor,,,,,,1)]"

Table 12-7. Parameters for the AddItem function

Parameter

Return Main Page Previous Page Next Page

®Online Book Reader