VBA doesn`t know the DataTable data type and VB.Net doesn`t know what to do
with the recordset object type
so there is your problem
well you could solve this in diferent ways
1 . you could make a method in your VB.Net class that loads the data by
passing it`s tablename ( with ADO.Net through Oledb )
like this
Friend Function fDtDataExecute(ByVal SQL As String) As DataTable
Try
Dim da As New OleDbDataAdapter
da.SelectCommand = New OleDbCommand(SQL, _objCon)
fDtDataExecute = New DataTable
da.Fill(fDtDataExecute)
da.Dispose()
Catch ex As Exception
_exception = ex
End Try
End Function
2.
or you could set a reference to classic ADO in VB.Net and work with the
passed recordset
( the two types are now the same in VBA and VB.Net and can be passed from
one to the other )
please note that the first method will give you the highest performance
regards
Michel Posseth
"Mark" <Ma**@discussions.microsoft.com> wrote in message
news:F7**********************************@microsof t.com...
Hello -
From an Access VBA module, I'm trying to pass a Table to a VB.Net class.
I'm getting the following error running the VBA:
"Unable to cast object of type System._ComObject to type
System.Data.Datatable"
The code resulting in the error looks like the following
In VBA:
Dim mclass As myClass
Set mclass = New myClass
Set mclass.ContractTable = CurrentDb().OpenRecordset("Contract")
In VB.Net:
Public Class myClass
Private myrstContract As Data.DataTable
WriteOnly Property ContractTable() As DataTable
Set(ByVal Value As DataTable)
myrstContract = Value
End Set
End Property
End Class
Suggestions?
Thank you as always,
Mark