Expose overloaded constructors in Access2003

G

Guest

I built a class in VB.NET that has an overloaded constructor. It can either accept nothing, a string or an object

Public Sub New(
MyBase.New(
End Su

Public Sub New(ByVal strName As String
MyBase.New(
'... Do init with strNam
End Su

Public Sub New(ByVal oObj As MyObjClass
MyBase.New(
'... Do init with oOb
End Su

If I enter these lines in Access
dim x as MyClas
set x = new MyClass("SomeName"
then I get an error

How can I expose all constructors of my class in Access2003 or VB6

All help will be very much appreciated

Ver
 
C

CJ Taylor

Hey Vera,

My experience is limited in this area, but doesn't Access 2003 only support
VBA? If so, do you have to expose your VB.NET class to COM at that point?

Again, not sure, but we were doing some GP work a little bit ago and had to
expose some .NET classes to COM to get it to work with VBA.

Hope it helps some,
CJ
Vera said:
I built a class in VB.NET that has an overloaded constructor. It can
either accept nothing, a string or an object:
 
H

Herfried K. Wagner [MVP]

* "=?Utf-8?B?VmVyYQ==?= said:
I built a class in VB.NET that has an overloaded constructor. It can either accept nothing, a string or an object:

Public Sub New()
MyBase.New()
End Sub

Public Sub New(ByVal strName As String)
MyBase.New()
'... Do init with strName
End Sub

Public Sub New(ByVal oObj As MyObjClass)
MyBase.New()
'... Do init with oObj
End Sub

If I enter these lines in Access:
dim x as MyClass
set x = new MyClass("SomeName")
then I get an error.

How can I expose all constructors of my class in Access2003 or VB6?

How do you use the .NET Class inside Access? If you are using VBA, I
seriously doubt that you can use parameterized ctors.
 
J

Jay B. Harlow [MVP - Outlook]

Vera,
How can I expose all constructors of my class in Access2003 or VB6?
Short answer: You don't.

Long answer: You can't as Access 2003 is COM based, COM does not support
overloading methods, nor does it support any constructors other then the
default constructor.

What you may want to do is to create a Factory Class (a second class) that
has two methods on it that create your first class based on a string or
based on an object.

Hope this helps
Jay

Vera said:
I built a class in VB.NET that has an overloaded constructor. It can
either accept nothing, a string or an object:
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top