Solved

CreateObject and Type Mismatch

Posted on 2000-02-22
16
491 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
Problems using Powershell and Active Directory?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

 
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
 
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

Problems using Powershell and Active Directory?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

Question has a verified solution.

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

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…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…

809 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