PDA

View Full Version : [SOLVED:] VBA Coding Help



SailFL
08-19-2005, 09:54 AM
I have created a user-defined data type which is a structure. I have declared the variable as a public type:


Type PaverArea
Company As String * 30
PaverCode As Integer
End Type

Public JobArea(1 to 9) as PaverArea

I placed both of these in the General declarations. But I get the following from the compiler: "Cannot define Public user-defined type within an Object Module" The code is part of a UserForm.

I thought this would be the place to put it. Where do I put my user-defined data type and public declared variable? And The book I have says, You define custom data types at the top of your module, before any procedures. If it is not General where would that be?

Thanks

mdmackillop
08-19-2005, 10:41 AM
Hi Nils,
Add a standard module and put your code there.
Regards
Malcolm

Tommy
08-19-2005, 10:41 AM
What that error means is the form is an object model,
That a user defined type must be defined outside of it As in a module:


Option Base 1 '<- If you want everything to start off with _
a base 1 instead of 0 use Option Base 1
'this is not required to place at in front, _
I do is all, gives me a quick and easy way to tell it _
is a UDT (user defined type)
Type tPaverArea
Company As String * 30
PaverCode As Integer
End Type

Public JobArea(1 To 9) As tPaverArea

Bob Phillips
08-19-2005, 10:50 AM
I have created a user-defined data type which is a structure. I have declared the variable as a public type:

Type PaverArea
Company As String * 30
PaverCode As Integer
End Type

Public JobArea(1 to 9) as PaverArea

I placed both of these in the General declarations. But I get the following from the compiler: "Cannot define Public user-defined type within an Object Module" The code is part of a UserForm.

I thought this would be the place to put it. Where do I put my user-defined data type and public declared variable? And The book I have says, You define custom data types at the top of your module, before any procedures. If it is not General where would that be?

Thanks

If using in a class module, which a form is, just make them Private.