Solved

CreateObject and Type Mismatch

Posted on 2000-02-22
16
494 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
Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
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…
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…

808 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