?
Solved

CreateObject and Type Mismatch

Posted on 2000-02-22
16
Medium Priority
?
502 Views
Last Modified: 2008-02-26
The following piece of code is used to start up any addons to a piece of software I am working on.  It gets the names of the addon from a db and then uses create object to create them.  CreateObject creates the object(I can see them listed in my process list) however I get a 'Type Mismatch', when the set line gets called.  The weird part is it worked a single time when the object had nothing in it.  I coded what I needed and not it wont work, I even tried going back to the original empty object.
---
(General)
Dim AddOn() as Object
-----
(MySub)
    If rsAddOn.RecordCount Then
        ReDim AddOn(rsAddOn.RecordCount)
        rsAddOn.MoveFirst
        For i = 0 To rsAddOn.RecordCount - 1
            Set AddOn(i) = CreateObject(rsAddOn.Fields("Name"))
            rsAddOn.MoveNext
        Next i
    End If
0
Comment
Question by:Spri
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 8
  • 4
  • 3
  • +1
16 Comments
 
LVL 9

Expert Comment

by:Ruchi
ID: 2547289
You need to use Set...

e.g.
dim AddOn() as Object
Set Addon = ..........
0
 
LVL 9

Expert Comment

by:Ruchi
ID: 2547295
I meant you need to declare the above code before using rs.AddOn..

I don't know how to explain..
0
 

Author Comment

by:Spri
ID: 2547304
rsAddOn is declared in previous code and is working properly.
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 9

Expert Comment

by:Ruchi
ID: 2547353
Okay. According to the MSDN article, CreateObject function is to create and return to a reference to an ActiveX. CreateObject is typically used with objects that are created from ActiveX servers. Are you working with ActiveX server?

If not, try using (I think)

Dim Addon() as ...
Set AddOn(i) = New(rsAddOn.Fields("Name"))
0
 

Author Comment

by:Spri
ID: 2547361
I am getting the object from an ActiveX EXE.

I have used CreateObject many times before using the same type of setup however my Dim of AddOn must be at Object because the type of these objects can change.  From my understanding it is called late-binding(i could be wront)
0
 
LVL 4

Expert Comment

by:wqw
ID: 2547401
first, i do hope that rsAddOn.Fields("Name") is of string type. think if its unicode string. basicly use CStr, whatever...

second, i do hope you've ReDim-ed your array somewhere before using it

</wqw>
           
0
 

Author Comment

by:Spri
ID: 2547413
The array was redimmed in the code i posted above.  The field is a string otherwise the object would not be created.
0
 
LVL 4

Accepted Solution

by:
wqw earned 300 total points
ID: 2547464
That's what i mean. Your object is not created at all. Your Type Mismatch is in the right part of the expression.

Try
    Dim o as Object
    Set o = CreateObject(...)
    Set AddOn(i) = o

Where does it break?

</wqw>
0
 
LVL 4

Expert Comment

by:wqw
ID: 2547506
That's what i mean. Your object is not created at all. Your Type Mismatch is in the right part of the expression.

Try
    Dim o as Object
    Set o = CreateObject(...)
    Set AddOn(i) = o

Where does it break?

</wqw>
0
 
LVL 4

Expert Comment

by:wqw
ID: 2547537
That's what i mean. Your object is not created at all. Your Type Mismatch is in the right part of the expression.

Try
    Dim o as Object
    Set o = CreateObject(...)
    Set AddOn(i) = o

Where does it break?

</wqw>
0
 
LVL 4

Expert Comment

by:wqw
ID: 2547570
That's what i mean. Your object is not created at all. Your Type Mismatch is in the right part of the expression.

Try
    Dim o as Object
    Set o = CreateObject(...)
    Set AddOn(i) = o

Where does it break?

</wqw>
0
 
LVL 4

Expert Comment

by:wqw
ID: 2547592
That's what i mean. Your object is not created at all. Your Type Mismatch is in the right part of the expression.

Try
    Dim o as Object
    Set o = CreateObject(...)
    Set AddOn(i) = o

Where does it break?

</wqw>
0
 
LVL 4

Expert Comment

by:wqw
ID: 2547628
That's what i mean. Your object is not created at all. Your Type Mismatch is in the right part of the expression.

Try
    Dim o as Object
    Set o = CreateObject(...)
    Set AddOn(i) = o

Where does it break?

</wqw>
0
 
LVL 6

Expert Comment

by:Marine
ID: 2547682
Don't forget to create a reference to that object as well. You don't really have to use CreateOjbect() if that object supports keyword New if not then you only use it.
Dim objMail as Object
Set objMail = CreateObject("CDONTS.NewMail")
this creates the object now allits methods and properties are available to me.
0
 

Author Comment

by:Spri
ID: 2548145
Because of time constraints I started the object from scratch and decided to move it to an ActiveX DLL and it works..but this is forcing a major coding change..

Thanks everyone.

Spri
0
 
LVL 4

Expert Comment

by:wqw
ID: 2549422
on second thought, you could've missed an error in Class_Initialize of your object. :-)

10x anyway

</wqw>
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Suggested Courses
Course of the Month9 days, 19 hours left to enroll

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question