In PowerShell, how do you access DAO enumeration constants, such as RecordsetTypeEnum dbOpenTable (1) or DataTypeEnum adVarNumeric (139)? Right now, I'm simply putting them in as magic numbers, but it would be much cleaner and easier to read to refer to the proper constants.
Asked
Active
Viewed 135 times
2 Answers
0
You could define a custom enum
type with the names needed:
enum DAODataType {
adBigInt = 0x14
adBinary = 0x80
adBoolean = 0x0B
adBSTR = 0x08
adChapter = 0x88
adChar = 0x81
adCurrency = 0x06
adDate = 0x07
adDBDate = 0x85
adDBTime = 0x86
adDBTimeStamp = 0x87
adDecimal = 0x0E
adDouble = 0x05
adEmpty = 0x00
adError = 0x0A
adFileTime = 0x40
adGUID = 0x48
adIDispatch = 0x09
adInteger = 0x03
adIUnknown = 0x0D
adLongVarBinary = 0xCD
adLongVarChar = 0xC9
adLongVarWChar = 0xCB
adNumeric = 0x83
adPropVariant = 0x8A
adSingle = 0x04
adSmallInt = 0x02
adTinyInt = 0x10
adUnsignedBigInt = 0x15
adUnsignedInt = 0x13
adUnsignedSmallInt = 0x12
adUnsignedTinyInt = 0x11
adUserDefined = 0x84
adVarBinary = 0xCC
adVarChar = 0xC8
adVariant = 0x0C
adVarNumeric = 0x8B
adVarWChar = 0xCA
adWChar = 0x82
}
Then pass [DAODataType]::adVarNumeric
instead of 139

Mathias R. Jessen
- 157,619
- 12
- 148
- 206
-
I was hoping more for referencing the original DAO enum, rather than building my own. Something like [DAO.RecordsetTypeEnum]::dbOpenTable (but that doesn't work for some reason). – whairst Jan 05 '22 at 14:09
-
@whairst For that, you'll need to import [the appropriate interop assembly](https://learn.microsoft.com/en-us/visualstudio/vsto/office-primary-interop-assemblies?view=vs-2022) – Mathias R. Jessen Jan 05 '22 at 14:11
0
For RecordsetTypeEnum dbOpenTable (which comes from Access), you can use:
[Reflection.Assembly]::LoadWithPartialName("Microsoft.Office.Interop.Access.Dao") | Out-null
[int][Microsoft.Office.Interop.Access.Dao.RecordsetTypeEnum]::dbOpenTable
For DataTypeEnum adVarNumeric (which comes from ADODB, not Access) you can use:
[Reflection.Assembly]::LoadWithPartialName("ADODB") | Out-null
[int][ADODB.DataTypeEnum]::adVarNumeric

whairst
- 43
- 6