Solved

User Defined Types

Posted on 2001-07-02
12
169 Views
Last Modified: 2012-06-27
Could someone please tell me what the following statement means and how can I get around it. I am trying to use the IsEmpty function on a user-defined type.

"Only User-Defined Types defined in Public Object modules can be coerced to or from a variant or passed to late-bound functions."

Here is my if statement I am trying to use:
If IsEmpty(strPMActivities) = False Then

My strPMActivities() as udtPMData is my user defined type and is declared with in a function and is passed to other functions.

Liz
0
Comment
Question by:eware
  • 5
  • 5
  • 2
12 Comments
 
LVL 38

Expert Comment

by:PaulHews
ID: 6246077
IsEmpty only returns meaningful information for variants.  UDT is not a variant, so find another way to figure out if it is initialized or not.
0
 
LVL 16

Expert Comment

by:Richie_Simonetti
ID: 6246157
could you post some more code where you use it?
0
 

Author Comment

by:eware
ID: 6246170
If IsEmpty(strPMActivities) = False Then
    For I = 1 To UBound(strPMActivities)
        Set lsvData = frmRunSchedule.lsvPMSchedule.ListItems.Add(, ,                strPMActivities(I).intPMID)
        With lsvData
            .SubItems(1) = strPMActivities(I).strMesaPMID
            .SubItems(2) = "SCHEDULED"
            .SubItems(3) = strPMActivities(I).strActName
        End With
    Next I
end if

Basically says if there is data in the array, do the for loop below. I have many udt's and have tried a function that will send me back an integer, 0 for no data and 1 for data, but I would need a function for each data type.

Liz
0
 
LVL 38

Accepted Solution

by:
PaulHews earned 100 total points
ID: 6246182
>>>
Basically says if there is data in the array, do the for loop below. I have many udt's and have tried
a function that will send me back an integer, 0 for no data and 1 for data, but I would need a function
for each data type.
<<<

Use error trapping on Ubound

dim lngUBound as long

On Error resume next
lngUbound = Ubound(strPMActivities)


If err.Number = 0 then
   On Error Goto 0
   For I = 1 To lngUBound
       Set lsvData = frmRunSchedule.lsvPMSchedule.ListItems.Add(, ,                strPMActivities(I).intPMID)
       With lsvData
           .SubItems(1) = strPMActivities(I).strMesaPMID
           .SubItems(2) = "SCHEDULED"
           .SubItems(3) = strPMActivities(I).strActName
       End With
   Next I
end if
0
 
LVL 38

Expert Comment

by:PaulHews
ID: 6246185
Might want to add this at the end

On Error Goto 0


Otherwise, error trapping still in effect if no data in array.
0
 

Author Comment

by:eware
ID: 6246240
Could I have multiple On Errors in a function/
0
Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 38

Expert Comment

by:PaulHews
ID: 6246250
You can't nest them if that's what you mean.
0
 

Author Comment

by:eware
ID: 6246255
What I meant by my previous question was I have On Error Goto Errorhandler as well. Is it possible to have multiple On Errors and it know which one to go to?
0
 
LVL 38

Expert Comment

by:PaulHews
ID: 6246257
But you can temporarily change your default error handler to take something different...

On Error goto errHandler  'default error handling

....code and stuff

on error resume next  'change default handler
if err.number = 0
  ''blablabla
end if
on error goto errHandler  'turn default handler back on
0
 
LVL 16

Expert Comment

by:Richie_Simonetti
ID: 6246432
A little comment, what is strPMActivities? Array or UDT?
i missed something!
0
 

Author Comment

by:eware
ID: 6246480
I am glad that someone knows how to catch these errors. It is really difficult when you can't find an answer in the help. It is alot of work because I have these ubounds everywhere, but If it does what I need it to do, I will use it. Thank you for your help.

Liz
0
 

Author Comment

by:eware
ID: 6246487
strPMActivities is a UDT.
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

707 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now