User defined Type


G

Guest

I am trying to debug existing code and the following declaration won't work.

Private x2App As Excel.Application

I keep getting an error msg stating "user defined type not defined"

Here is the Type statement I have in the declaration section of my class
module.

Private Type UserDefinedType
Application As Object
Workbook As Object
Worksheet As Object
End Type

Private Type UserDefinedType2
Connection As Object
Command As Object
Parameter As Object
Recordset As Object
End Type

Option Explicit
Dim Excel(1 To 3) As UserDefinedType
Dim ADODB(1 To 19) As UserDefinedType2

Any solutions?
 
Ad

Advertisements

G

Guest

try changing
Dim Excel(1 To 3) As UserDefinedType
to
Dim udtExcel(1 To 3) As UserDefinedType

Same deal with ADODB. Both Excel and ADODB are reserved so you don't really
want to use them as variable names...
 
G

Guest

Jim, I tried changing the Excel reference to MyPaige and the ADODB to
MyHookUp and got the same error msg. Any other ideas?
 
G

Guest

As a guess you have

Option Explicit
Dim Excel(1 To 3) As UserDefinedType
Dim ADODB(1 To 19) As UserDefinedType2

in a module somewhere and your UDT's in the Class??? Then a couple of
things. You can not declare a UDT in a Class. Since your UDT are declared
private you need to have all of the declarations in one module... Try this.
Start a new spreadsheet and add a module to it. Paste the following and it
will compile just fine...

Option Explicit
Dim objExcel(1 To 3) As UserDefinedType
Dim objADODB(1 To 19) As UserDefinedType2

Public Type UserDefinedType
Application As Object
Workbook As Object
Worksheet As Object
End Type

Private Type UserDefinedType2
Connection As Object
Command As Object
Parameter As Object
Recordset As Object
End Type
 
Ad

Advertisements

G

Guest

Thank you sir, I will try that.
--
TWN


Jim Thomlinson said:
As a guess you have

Option Explicit
Dim Excel(1 To 3) As UserDefinedType
Dim ADODB(1 To 19) As UserDefinedType2

in a module somewhere and your UDT's in the Class??? Then a couple of
things. You can not declare a UDT in a Class. Since your UDT are declared
private you need to have all of the declarations in one module... Try this.
Start a new spreadsheet and add a module to it. Paste the following and it
will compile just fine...

Option Explicit
Dim objExcel(1 To 3) As UserDefinedType
Dim objADODB(1 To 19) As UserDefinedType2

Public Type UserDefinedType
Application As Object
Workbook As Object
Worksheet As Object
End Type

Private Type UserDefinedType2
Connection As Object
Command As Object
Parameter As Object
Recordset As Object
End Type
 
Ad

Advertisements


Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top