Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 489
Default User-defined Type Issue

I have a UDF below that is located in a Standard Module.

Type Totals
COGS As Double
Material As Double
Labor As Double
UnitPrice As Currency
QuotePrice As Currency
End Type

I declared a Public Variable in another Standard Module like this.

Public Total As Totals

For some reason when I use Total with the With...End With Statement in the
code below VBA is throwing an exception stating "With object must be
user-defined type, variant or object". Anybody know why?

Sub Test()

With Total

' determines labor effiency % and COGS %
Select Case Val(tbxQuantity)
Case Is = 1
.COGS = 1.1
Case Is = 2
.COGS = 1.08
Case Is = 3
.COGS = 1.05
End Select

.Material = 300
.Labor = 1000
End With

End Sub

--
Cheers,
Ryan
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,298
Default User-defined Type Issue

to use totals type you'd need to be absolute

ie

some_material = total.material

an alternative would be to open a new CLASS MODULE, name it cTotals and give
it the variables that you gave to the type.

now you'd SET total = New cTotals

as total is an object of class cTotals, you can use the WITH method as you
showed.












"Ryan H" wrote:

I have a UDF below that is located in a Standard Module.

Type Totals
COGS As Double
Material As Double
Labor As Double
UnitPrice As Currency
QuotePrice As Currency
End Type

I declared a Public Variable in another Standard Module like this.

Public Total As Totals

For some reason when I use Total with the With...End With Statement in the
code below VBA is throwing an exception stating "With object must be
user-defined type, variant or object". Anybody know why?

Sub Test()

With Total

' determines labor effiency % and COGS %
Select Case Val(tbxQuantity)
Case Is = 1
.COGS = 1.1
Case Is = 2
.COGS = 1.08
Case Is = 3
.COGS = 1.05
End Select

.Material = 300
.Labor = 1000
End With

End Sub

--
Cheers,
Ryan

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 489
Default User-defined Type Issue

I reed the with statement help and it said it could be used with any
user-defined type. Do you know why it wouldn't work in my application?


--
Cheers,
Ryan


"Patrick Molloy" wrote:

to use totals type you'd need to be absolute

ie

some_material = total.material

an alternative would be to open a new CLASS MODULE, name it cTotals and give
it the variables that you gave to the type.

now you'd SET total = New cTotals

as total is an object of class cTotals, you can use the WITH method as you
showed.












"Ryan H" wrote:

I have a UDF below that is located in a Standard Module.

Type Totals
COGS As Double
Material As Double
Labor As Double
UnitPrice As Currency
QuotePrice As Currency
End Type

I declared a Public Variable in another Standard Module like this.

Public Total As Totals

For some reason when I use Total with the With...End With Statement in the
code below VBA is throwing an exception stating "With object must be
user-defined type, variant or object". Anybody know why?

Sub Test()

With Total

' determines labor effiency % and COGS %
Select Case Val(tbxQuantity)
Case Is = 1
.COGS = 1.1
Case Is = 2
.COGS = 1.08
Case Is = 3
.COGS = 1.05
End Select

.Material = 300
.Labor = 1000
End With

End Sub

--
Cheers,
Ryan

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,298
Default User-defined Type Issue

Your code was fine - all I had to do was set some value in tbxQuantity

making sure
OPTION EXPLICIT
is at the top of each module would have highlighted this

"Ryan H" wrote:

I reed the with statement help and it said it could be used with any
user-defined type. Do you know why it wouldn't work in my application?


--
Cheers,
Ryan


"Patrick Molloy" wrote:

to use totals type you'd need to be absolute

ie

some_material = total.material

an alternative would be to open a new CLASS MODULE, name it cTotals and give
it the variables that you gave to the type.

now you'd SET total = New cTotals

as total is an object of class cTotals, you can use the WITH method as you
showed.












"Ryan H" wrote:

I have a UDF below that is located in a Standard Module.

Type Totals
COGS As Double
Material As Double
Labor As Double
UnitPrice As Currency
QuotePrice As Currency
End Type

I declared a Public Variable in another Standard Module like this.

Public Total As Totals

For some reason when I use Total with the With...End With Statement in the
code below VBA is throwing an exception stating "With object must be
user-defined type, variant or object". Anybody know why?

Sub Test()

With Total

' determines labor effiency % and COGS %
Select Case Val(tbxQuantity)
Case Is = 1
.COGS = 1.1
Case Is = 2
.COGS = 1.08
Case Is = 3
.COGS = 1.05
End Select

.Material = 300
.Labor = 1000
End With

End Sub

--
Cheers,
Ryan

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,934
Default User-defined Type Issue

I just tried it out and your code worked fine in my test. When it fails,
what line does debugger stop on and what is the error message it shows you?

--
Rick (MVP - Excel)


"Ryan H" wrote in message
...
I reed the with statement help and it said it could be used with any
user-defined type. Do you know why it wouldn't work in my application?


--
Cheers,
Ryan


"Patrick Molloy" wrote:

to use totals type you'd need to be absolute

ie

some_material = total.material

an alternative would be to open a new CLASS MODULE, name it cTotals and
give
it the variables that you gave to the type.

now you'd SET total = New cTotals

as total is an object of class cTotals, you can use the WITH method as
you
showed.












"Ryan H" wrote:

I have a UDF below that is located in a Standard Module.

Type Totals
COGS As Double
Material As Double
Labor As Double
UnitPrice As Currency
QuotePrice As Currency
End Type

I declared a Public Variable in another Standard Module like this.

Public Total As Totals

For some reason when I use Total with the With...End With Statement in
the
code below VBA is throwing an exception stating "With object must be
user-defined type, variant or object". Anybody know why?

Sub Test()

With Total

' determines labor effiency % and COGS %
Select Case Val(tbxQuantity)
Case Is = 1
.COGS = 1.1
Case Is = 2
.COGS = 1.08
Case Is = 3
.COGS = 1.05
End Select

.Material = 300
.Labor = 1000
End With

End Sub

--
Cheers,
Ryan




  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 489
Default User-defined Type Issue

Yes I have OPTION EXPLICIT at the top of all my modules. But I'm really
scratching my head on why the compile error is happening saying "With object
must be user-defined type, variant or object". My Total is a UDF, so why am
I still getting this error?

Thanks in advance!
--
Cheers,
Ryan


"Patrick Molloy" wrote:

Your code was fine - all I had to do was set some value in tbxQuantity

making sure
OPTION EXPLICIT
is at the top of each module would have highlighted this

"Ryan H" wrote:

I reed the with statement help and it said it could be used with any
user-defined type. Do you know why it wouldn't work in my application?


--
Cheers,
Ryan


"Patrick Molloy" wrote:

to use totals type you'd need to be absolute

ie

some_material = total.material

an alternative would be to open a new CLASS MODULE, name it cTotals and give
it the variables that you gave to the type.

now you'd SET total = New cTotals

as total is an object of class cTotals, you can use the WITH method as you
showed.












"Ryan H" wrote:

I have a UDF below that is located in a Standard Module.

Type Totals
COGS As Double
Material As Double
Labor As Double
UnitPrice As Currency
QuotePrice As Currency
End Type

I declared a Public Variable in another Standard Module like this.

Public Total As Totals

For some reason when I use Total with the With...End With Statement in the
code below VBA is throwing an exception stating "With object must be
user-defined type, variant or object". Anybody know why?

Sub Test()

With Total

' determines labor effiency % and COGS %
Select Case Val(tbxQuantity)
Case Is = 1
.COGS = 1.1
Case Is = 2
.COGS = 1.08
Case Is = 3
.COGS = 1.05
End Select

.Material = 300
.Labor = 1000
End With

End Sub

--
Cheers,
Ryan

  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 489
Default User-defined Type Issue

If I put Dim Total As Totals at the top of each module the code wants to
work. But for some reason VBA does not want to recognize Public Total As
Totals in another module, why?

--
Cheers,
Ryan


"Patrick Molloy" wrote:

Your code was fine - all I had to do was set some value in tbxQuantity

making sure
OPTION EXPLICIT
is at the top of each module would have highlighted this

"Ryan H" wrote:

I reed the with statement help and it said it could be used with any
user-defined type. Do you know why it wouldn't work in my application?


--
Cheers,
Ryan


"Patrick Molloy" wrote:

to use totals type you'd need to be absolute

ie

some_material = total.material

an alternative would be to open a new CLASS MODULE, name it cTotals and give
it the variables that you gave to the type.

now you'd SET total = New cTotals

as total is an object of class cTotals, you can use the WITH method as you
showed.












"Ryan H" wrote:

I have a UDF below that is located in a Standard Module.

Type Totals
COGS As Double
Material As Double
Labor As Double
UnitPrice As Currency
QuotePrice As Currency
End Type

I declared a Public Variable in another Standard Module like this.

Public Total As Totals

For some reason when I use Total with the With...End With Statement in the
code below VBA is throwing an exception stating "With object must be
user-defined type, variant or object". Anybody know why?

Sub Test()

With Total

' determines labor effiency % and COGS %
Select Case Val(tbxQuantity)
Case Is = 1
.COGS = 1.1
Case Is = 2
.COGS = 1.08
Case Is = 3
.COGS = 1.05
End Select

.Material = 300
.Labor = 1000
End With

End Sub

--
Cheers,
Ryan

  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default User-defined Type Issue

Just a guess...

You didn't declare another variable (within that sub or at module level in that
sub's module) as Total, did you?

If you did, then your code will find that one before it sees the public
declaration in a different module.

Ryan H wrote:

I have a UDF below that is located in a Standard Module.

Type Totals
COGS As Double
Material As Double
Labor As Double
UnitPrice As Currency
QuotePrice As Currency
End Type

I declared a Public Variable in another Standard Module like this.

Public Total As Totals

For some reason when I use Total with the With...End With Statement in the
code below VBA is throwing an exception stating "With object must be
user-defined type, variant or object". Anybody know why?

Sub Test()

With Total

' determines labor effiency % and COGS %
Select Case Val(tbxQuantity)
Case Is = 1
.COGS = 1.1
Case Is = 2
.COGS = 1.08
Case Is = 3
.COGS = 1.05
End Select

.Material = 300
.Labor = 1000
End With

End Sub

--
Cheers,
Ryan


--

Dave Peterson
  #9   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 489
Default User-defined Type Issue

Ok figured out why. The Module Name was Total as well. Excel must have
gotten the module Name Total and the Type Total confused. Everything works
fine now.

Thanks for the help!
--
Cheers,
Ryan


"Ryan H" wrote:

If I put Dim Total As Totals at the top of each module the code wants to
work. But for some reason VBA does not want to recognize Public Total As
Totals in another module, why?

--
Cheers,
Ryan


"Patrick Molloy" wrote:

Your code was fine - all I had to do was set some value in tbxQuantity

making sure
OPTION EXPLICIT
is at the top of each module would have highlighted this

"Ryan H" wrote:

I reed the with statement help and it said it could be used with any
user-defined type. Do you know why it wouldn't work in my application?


--
Cheers,
Ryan


"Patrick Molloy" wrote:

to use totals type you'd need to be absolute

ie

some_material = total.material

an alternative would be to open a new CLASS MODULE, name it cTotals and give
it the variables that you gave to the type.

now you'd SET total = New cTotals

as total is an object of class cTotals, you can use the WITH method as you
showed.












"Ryan H" wrote:

I have a UDF below that is located in a Standard Module.

Type Totals
COGS As Double
Material As Double
Labor As Double
UnitPrice As Currency
QuotePrice As Currency
End Type

I declared a Public Variable in another Standard Module like this.

Public Total As Totals

For some reason when I use Total with the With...End With Statement in the
code below VBA is throwing an exception stating "With object must be
user-defined type, variant or object". Anybody know why?

Sub Test()

With Total

' determines labor effiency % and COGS %
Select Case Val(tbxQuantity)
Case Is = 1
.COGS = 1.1
Case Is = 2
.COGS = 1.08
Case Is = 3
.COGS = 1.05
End Select

.Material = 300
.Labor = 1000
End With

End Sub

--
Cheers,
Ryan

  #10   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 8,520
Default User-defined Type Issue

It is considered as a good practice to follow some sort of naming convention
for variables, modules, userforms, user controls etc; so as to avoid such
confusions ..

modTotal/gmdTotal to represent module/general module
typTotal to represent custom Type..
frmMain to represent userform
strMessage to represent string variable
cmdOK to represent command button
clsMain to represent Class module

If this post helps click Yes
---------------
Jacob Skaria


"Ryan H" wrote:

Ok figured out why. The Module Name was Total as well. Excel must have
gotten the module Name Total and the Type Total confused. Everything works
fine now.

Thanks for the help!
--
Cheers,
Ryan


"Ryan H" wrote:

If I put Dim Total As Totals at the top of each module the code wants to
work. But for some reason VBA does not want to recognize Public Total As
Totals in another module, why?

--
Cheers,
Ryan


"Patrick Molloy" wrote:

Your code was fine - all I had to do was set some value in tbxQuantity

making sure
OPTION EXPLICIT
is at the top of each module would have highlighted this

"Ryan H" wrote:

I reed the with statement help and it said it could be used with any
user-defined type. Do you know why it wouldn't work in my application?


--
Cheers,
Ryan


"Patrick Molloy" wrote:

to use totals type you'd need to be absolute

ie

some_material = total.material

an alternative would be to open a new CLASS MODULE, name it cTotals and give
it the variables that you gave to the type.

now you'd SET total = New cTotals

as total is an object of class cTotals, you can use the WITH method as you
showed.












"Ryan H" wrote:

I have a UDF below that is located in a Standard Module.

Type Totals
COGS As Double
Material As Double
Labor As Double
UnitPrice As Currency
QuotePrice As Currency
End Type

I declared a Public Variable in another Standard Module like this.

Public Total As Totals

For some reason when I use Total with the With...End With Statement in the
code below VBA is throwing an exception stating "With object must be
user-defined type, variant or object". Anybody know why?

Sub Test()

With Total

' determines labor effiency % and COGS %
Select Case Val(tbxQuantity)
Case Is = 1
.COGS = 1.1
Case Is = 2
.COGS = 1.08
Case Is = 3
.COGS = 1.05
End Select

.Material = 300
.Labor = 1000
End With

End Sub

--
Cheers,
Ryan



  #11   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,298
Default User-defined Type Issue

i wonder if the issue might have been picked up if you'd celected DEBUG /
COMPILE from the menu? I got "Expected variable or procedure, not module"



"Ryan H" wrote:

Ok figured out why. The Module Name was Total as well. Excel must have
gotten the module Name Total and the Type Total confused. Everything works
fine now.

Thanks for the help!
--
Cheers,
Ryan


"Ryan H" wrote:

If I put Dim Total As Totals at the top of each module the code wants to
work. But for some reason VBA does not want to recognize Public Total As
Totals in another module, why?

--
Cheers,
Ryan


"Patrick Molloy" wrote:

Your code was fine - all I had to do was set some value in tbxQuantity

making sure
OPTION EXPLICIT
is at the top of each module would have highlighted this

"Ryan H" wrote:

I reed the with statement help and it said it could be used with any
user-defined type. Do you know why it wouldn't work in my application?


--
Cheers,
Ryan


"Patrick Molloy" wrote:

to use totals type you'd need to be absolute

ie

some_material = total.material

an alternative would be to open a new CLASS MODULE, name it cTotals and give
it the variables that you gave to the type.

now you'd SET total = New cTotals

as total is an object of class cTotals, you can use the WITH method as you
showed.












"Ryan H" wrote:

I have a UDF below that is located in a Standard Module.

Type Totals
COGS As Double
Material As Double
Labor As Double
UnitPrice As Currency
QuotePrice As Currency
End Type

I declared a Public Variable in another Standard Module like this.

Public Total As Totals

For some reason when I use Total with the With...End With Statement in the
code below VBA is throwing an exception stating "With object must be
user-defined type, variant or object". Anybody know why?

Sub Test()

With Total

' determines labor effiency % and COGS %
Select Case Val(tbxQuantity)
Case Is = 1
.COGS = 1.1
Case Is = 2
.COGS = 1.08
Case Is = 3
.COGS = 1.05
End Select

.Material = 300
.Labor = 1000
End With

End Sub

--
Cheers,
Ryan

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Compile error: User-defined type not defined Ayo Excel Programming 3 April 23rd 09 07:42 PM
Help: Compile error: type mismatch: array or user defined type expected lvcha.gouqizi Excel Programming 1 October 31st 05 08:20 PM
Workspace faux user-defined type not defined Chris S[_2_] Excel Programming 3 November 11th 04 05:51 PM
User-defined data type; Error: Only User-defined types... tiger_PRM Excel Programming 1 July 18th 04 03:32 PM
Word.Document - user defined type not defined jowatkins[_7_] Excel Programming 0 January 20th 04 08:46 AM


All times are GMT +1. The time now is 04:29 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"