This project has moved. For the latest updates, please go here.

DAOApi.Property Assignment Error => Class not exists: NetOffice.ExcelApi.Property

Mar 12, 2015 at 9:42 AM
Hi Sebastian,

Firstly thanks for such a great product. We have multiple versions of MS Office and NetOffice just makes implementation into this type of environment easy.

I have a strange error with DAOApi.Property. When the DAOApi.Properties(i) is assigned to a DAOApi.Property variable the following error occurs:

Class not exists: NetOffice.ExcelApi.Property

My Dev machine is Win7 Pro 64 with Office 2010 32 bit.

I much appreciate your assistance with this matter.

Cheers,

Gordon

The Method Code follows:

Private Function HasFieldProperty(ByRef checkField As Field,
                                      ByVal checkPropertyName As String) As Boolean

        ' Determine if the fieldToCheck has the 'Property Name' (eg: Format, Input Mask,....)
        Dim fldName = checkField.Name

        ' Check if PropertyName Exists
        Dim propertyExists As Boolean = False

        Dim fldProperty As NetOffice.DAOApi.Property = Nothing
        Dim fldProperties As NetOffice.DAOApi.Properties = Nothing

        Try
            fldProperties = checkField.Properties

            For i As Integer = 0 To fldProperties.Count - 1

                Dim fldPropertyName = fldProperties(i).Name ' Fails on this line
                If fldPropertyName = checkPropertyName.ToUpper Then
                    propertyExists = True
                    Exit For
                End If

            Next i

DisposeObjects:
            ' - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

        Catch ex As Exception
            Dim msg = innerExceptionMessage(ex)
            propertyExists = False

        Finally
            ' DisposeObjects (in Reverse Order)
            If Not IsNothing(fldProperty) AndAlso Not fldProperty.IsDisposed Then
                fldProperty.Dispose()
            End If
            If Not IsNothing(fldProperties) AndAlso Not fldProperties.IsDisposed Then
                fldProperties.Dispose()
            End If

        End Try

        Return propertyExists

    End Function
Coordinator
Mar 12, 2015 at 1:49 PM
Looks like ExcelApi.dll is not referenced (but note sure it has to be).

I need some more infos.

1) NetOffice version
2) Application Type, External Program or Addin( if addin which host application?)
3) Full qualified type name of your argument checkField (need info which is come from)

I want checkout the COM interface id's of Excel.Property and DAO.Property.
(may its the same id's, this is forbidden in COM but sometimes Microsoft goes crazy)

Sebastian
Mar 13, 2015 at 10:00 AM
Hi Sebastian,

Thanks for your prompt reply.

The NetOffice.ExcelApi is not referenced in the Access Project (I was confused when it came up with Excel and not Access as an Error)

1) NetOffice Version for NetOffice .Core, NetOffice .Access and NetOffice .Excel is 1.7.2.0
2) Application type is an external program. WPF UI calling set of NetOffice Access Functions (as per code snippets) or Excel Functions
3.) checkField source is as per following code:
 tdf => tdf.fields => fld.Type=4 => SetFieldProperty => HasFieldProperty
Pleased to send a sample project if that makes things easier.

Have great day.

Cheers,

Gordon.

Code for checkField source:

Region "Field Properties"

    Private Function SetLongFieldProperties(ByRef tdf As TableDef) As Boolean

        ' Property Attributes
        Dim propertyName As String = Nothing
        Dim propertyDataType As NetOffice.DAOApi.Enums.DataTypeEnum = Nothing
        Dim propertyValue As Object = Nothing

        ' Get the fields from the TableDef
        Dim fld As Field = Nothing
        Dim flds As Fields = tdf.Fields

        Dim result As Boolean = False

        Try
            For Each fld In flds

                Dim fldType = fld.Type

                Select Case fldType

                    Case 4

                        ' - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
                        ' Long Formatting
                        ' - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
                        propertyName = "Format"
                        propertyDataType = NetOffice.DAOApi.Enums.DataTypeEnum.dbText
                        propertyValue = "Standard"

                        SetFieldProperty(fld, propertyName, propertyDataType, propertyValue)
                        ' - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

                        propertyName = "DecimalPlaces"
                        propertyDataType = NetOffice.DAOApi.Enums.DataTypeEnum.dbByte
                        propertyValue = 0

                        SetFieldProperty(fld, propertyName, propertyDataType, propertyValue)
                        ' - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

                        propertyName = "ColumnWidth"
                        propertyDataType = NetOffice.DAOApi.Enums.DataTypeEnum.dbInteger
                        propertyValue = 1200

                        SetFieldProperty(fld, propertyName, propertyDataType, propertyValue)


                End Select

            Next fld

            result = True

DisposeObjects:
            ' - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

        Catch ex As Exception
            Dim msg = innerExceptionMessage(ex)
            result = False

        Finally
            ' DisposeObjects (in Reverse Order)
            If Not IsNothing(fld) AndAlso Not fld.IsDisposed Then
                fld.Dispose()
            End If
            If Not IsNothing(flds) AndAlso Not flds.IsDisposed Then
                flds.Dispose()
            End If

        End Try


        Return True

    End Function

    Private Function SetFieldProperty(ByRef fieldToSet As Field,
                                      ByVal propertyName As String,
                                      ByVal propertyDataType As NetOffice.DAOApi.Enums.DataTypeEnum,
                                      ByVal propertySetValue As Object) As Boolean

        ' Attempt to Set SetFieldProperty
        Dim fieldPropertySet As Boolean = False

        Try
            If HasFieldProperty(fieldToSet, propertyName) Then
                fieldToSet.Properties(propertyName).Value = propertySetValue
            Else
                fieldToSet.Properties.Append(fieldToSet.CreateProperty(propertyName, propertyDataType, propertySetValue))
            End If

            fieldPropertySet = True
DisposeObjects:
            ' - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

        Catch ex As Exception
            Dim msg = innerExceptionMessage(ex)
            fieldPropertySet = False

        Finally
            ' DisposeObjects (in Reverse Order)

        End Try

        Return fieldPropertySet

    End Function

    Private Function HasFieldProperty(ByRef checkField As Field,
                                      ByVal checkPropertyName As String) As Boolean

        ' Determine if the fieldToCheck has the 'Property Name' (eg: Format, Input Mask,....)
        Dim fldName = checkField.Name

        ' Check if PropertyName Exists
        Dim propertyExists As Boolean = False

        Dim fldProperty As NetOffice.DAOApi.Property = Nothing
        Dim fldProperties As NetOffice.DAOApi.Properties = Nothing

        Try
            fldProperties = checkField.Properties

            For i As Integer = 0 To fldProperties.Count - 1

                Dim fldPropertyName = fldProperties(i).Name
                If fldPropertyName = checkPropertyName.ToUpper Then
                    propertyExists = True
                    Exit For
                End If

            Next i

DisposeObjects:
            ' - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

        Catch ex As Exception
            Dim msg = innerExceptionMessage(ex)
            propertyExists = False

        Finally
            ' DisposeObjects (in Reverse Order)
            If Not IsNothing(fldProperty) AndAlso Not fldProperty.IsDisposed Then
                fldProperty.Dispose()
            End If
            If Not IsNothing(fldProperties) AndAlso Not fldProperties.IsDisposed Then
                fldProperties.Dispose()
            End If

        End Try

        Return propertyExists

    End Function
Coordinator
Mar 13, 2015 at 6:59 PM
A sample project is greatly appreciated.

please send to:
public.sebastian[at]web.de

(i need a mdb/accdb file or/and instructions how i can reproduce the exception)

BTW: Excel doesnt contains a type called "property" :o this is very strange.
i find ICustomProperty and CustomProperty only in my personal type lib analyzer tool.
(what i know currently: NetOffice failed to detect the correct type library which a single property instance type comes from.
i still believe on my duplicate interface id theory....)

lets pin point/fix this asap !

*Sebastian