Microsoft KB Archive/99319

= ACC: Finding the OLE ClassKey of an Embedded Object (1.x/2.0) =

Article ID: 99319

Article Last Modified on 5/9/2003

-

APPLIES TO


 * Microsoft Access 1.0 Standard Edition
 * Microsoft Access 1.1 Standard Edition
 * Microsoft Access 2.0 Standard Edition

-



This article was previously published under Q99319



SUMMARY
Advanced: Requires expert coding, interoperability, and multiuser skills.

Microsoft Access places a wrapper of information around an OLE object before it stores the object in a table. The Name and ClassKey of the object start at byte count 21 and are stored from there as two zero-terminating strings. By reading the field as a text field, you can parse out the ClassKey.

This article describes how to use Access Basic to find the ClassKey of an embedded object with an OLE-Object data type.

NOTE: This technique does not work if the OLE object is larger than 64K. In this case you'll see the error:

Object has no value



MORE INFORMATION
When an OLE object is stored in a table, the ClassKey is the second null-terminated string after the 20th byte in the object. It can be read as text with the following Access Basic code:

NOTE: In the following sample code, an underscore (_) is used as a line-continuation character. Remove the underscore from the end of the line when re-creating this code in Access Basic. Function GetObjectClass$ If IsNull(screen.activeform!Photo) Then GetObjectClass$ = &quot;n/a&quot; Else MyChunk$ = Mid(screen.activeform!Photo, 21, 40) NullOne% = InStr(1, MyChunk$, Chr$(0)) NullTwo% = InStr(NullOne% + 1, MyChunk$, Chr$(0)) GetObjectClass$ = Mid(MyChunk$, NullOne% + 1, _                              NullTwo% - NullOne% - 1) End If  End Function The GetObjectClass$ function first checks to see if the object is null and returns the value &quot;n/a&quot; if it is. If the object is not null, it assigns bytes 21 through 40 of the OLE object to the string MyChunk$ and then searches for the first null character, the next null character, and so forth. Finally, it sets the GetObjectClass$ function equal to the string between the two null characters.

Using the function provided above, a control on the Employees form of the sample database NWIND.MDB, with the properties below, displays the ClassKey for the Photo control:   ControlName: ObjClassKey ControlSource: =GetObjectClass This example returns &quot;PBRUSH&quot; for the first photo in the Employees table.

There are several different ways to use this information. RegQueryValue, a function contained in the Microsoft Windows SHELL.DLL file, uses the ClassKey to obtain information about that class from the REG.DAT file.

