Solved

CreateObject and Type Mismatch

Posted on 2000-02-22
16
490 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
  • 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
 
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 100 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

920 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now