Solved

CreateObject and Type Mismatch

Posted on 2000-02-22
16
489 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
What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

 
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

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
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…

708 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

17 Experts available now in Live!

Get 1:1 Help Now