Ruskin
26th June 2002, 08:20
I have had some requests, to use ENUM descriptions through VB. Unfortunately, due to the fact that they are binary objects, they do not come through correctly, using DAO or RDO (or ODBC). As a result, you must use ADO to get the objects. Even then, the enum description is not stored in the binary object. Thus, to get the enum description is rather complex. It involves the following;
a. determine the package combination of the current user
b. find the highest level VRC of that package combination
c. find the highest version of the table in that VRC level to find the domain used by the particular field (this is required, in case the table is customised and the domain of this field is changed)
d. find the highest version of the domain in that VRC level to find the description of the particular enum value (this is required, in case the domain is customised and the description has been changed)
Create a new project and ensure you have ADO activated for your project. To do this, from the menu bar, choose;
Project, References
Ensure 'Microsoft ActiveX Data Objects 2.5 Library' is selected
Add a module to your project and copy and paste the code from the attached text file 'ENUM_CD.TXT' into this module. You can then call this function with something like;
MsgBox FindItemType(<item code>)
If you want to find the enum description of a different table field, then simply plagerise this code and create your own function, similar to the FindItemType function (ensure that you call the 'PreChecksOkay' function the first time you run this, to set the global settings, such as user name, company, package combination, etc. Although, this code calls the PreChecksOkay function each time it runs, this function only needs to be called the first time this code is run. Therefore, you may wish to call this function in the Load event of your form and then not worry about calling it, when you get the enum descriptions).
NOTE: this example code assumes, that you have the tools tables and your company data tables, in the same database of your SQL server. If this is not the case, then you will need to create 2 connection objects. Also beware, this code will automatically connect to your SQL server, when activated, but will not disconnect. Ensure you disconnect (or close) the ADODB connection object either at the end of the 'FindItemType' function or when you close down your app. If you disconnect at the end of the FindItemType function, then ensure that you call the PreChecksOkay function each time, to re-establish the connection.
a. determine the package combination of the current user
b. find the highest level VRC of that package combination
c. find the highest version of the table in that VRC level to find the domain used by the particular field (this is required, in case the table is customised and the domain of this field is changed)
d. find the highest version of the domain in that VRC level to find the description of the particular enum value (this is required, in case the domain is customised and the description has been changed)
Create a new project and ensure you have ADO activated for your project. To do this, from the menu bar, choose;
Project, References
Ensure 'Microsoft ActiveX Data Objects 2.5 Library' is selected
Add a module to your project and copy and paste the code from the attached text file 'ENUM_CD.TXT' into this module. You can then call this function with something like;
MsgBox FindItemType(<item code>)
If you want to find the enum description of a different table field, then simply plagerise this code and create your own function, similar to the FindItemType function (ensure that you call the 'PreChecksOkay' function the first time you run this, to set the global settings, such as user name, company, package combination, etc. Although, this code calls the PreChecksOkay function each time it runs, this function only needs to be called the first time this code is run. Therefore, you may wish to call this function in the Load event of your form and then not worry about calling it, when you get the enum descriptions).
NOTE: this example code assumes, that you have the tools tables and your company data tables, in the same database of your SQL server. If this is not the case, then you will need to create 2 connection objects. Also beware, this code will automatically connect to your SQL server, when activated, but will not disconnect. Ensure you disconnect (or close) the ADODB connection object either at the end of the 'FindItemType' function or when you close down your app. If you disconnect at the end of the FindItemType function, then ensure that you call the PreChecksOkay function each time, to re-establish the connection.