[mso] Re: Problem with Class object in VBA Access2k

  • From: "Greg Chapman" <greg@xxxxxxxxxxxxx>
  • To: <mso@xxxxxxxxxxxxx>
  • Date: Wed, 25 Sep 2002 10:51:40 -0500

I've spent very little time working Class Modules so I'm not the last
source you ought to consider. However, I'm noticing you are mixing late
and early bound techniques in this code (set SomeVar=Nothing is late
bound; neither necessary or helpful for your routines, Dim SomeVar as
Something is Early bound, fast, reliable but requires that you have
first set a reference to the DLL, control or Class that contains
Something). First, what kind of variable have you defined
colConditionGrades to be (I'm expecting this to be an intrinsic value
and that you are setting the type to Collection)? Next, the very first
statement of this sub sets colConditionGrades to nothing, effectively
breaking the association between the variable and its data type. When
the code gets to the statement that adds the current clsCondition to the
collection colConditionGrades, there is no Add method available because
there is no instance of a collection associated with colConditionGrades.

So what happens if you comment out Set colConditionGrades = Nothing? If
it is to be a collection, it's doubtful that you want to keep breaking
the variable unless you're processing the collection's contents right
away and storing that data in some other structure. 

If we take Dian's comparison of a variable to a bucket, then a
collection is a dumpster that is being used to hold the contents of lots
of buckets. You generally don't fill the dumpster with bucketloads of
data and that you consider to be temporary. Go ahead and leave the
collection alone and add or remove from it as you need.  

Greg Chapman
http://www.mousetrax.com 
"Counting in binary is as easy as 01, 10, 11!
With thinking this clear, is coding really a good idea?"


> -----Original Message-----
> From: mso-bounce@xxxxxxxxxxxxx 
> [mailto:mso-bounce@xxxxxxxxxxxxx] On Behalf Of Alan Forster
> Sent: Wednesday, September 25, 2002 9:29 AM
> To: mso@xxxxxxxxxxxxx
> Subject: [mso] Problem with Class object in VBA Access2k
> 
> 
> 
> Hello,
> 
> I have defined a class module, classCondition.
> I have declared a public variable colConditionGrades in a 
> module. The sub below is used to populate the properties of 
> the class object and th= en add the class object to the collection.
> 
> Private Sub Build_colCondition()
>     Set colConditionGrades =3D Nothing
>     rstSurveyValues.MoveFirst
>     Do While (Not rstSurveyValues.EOF) And _
>              (Not IsNull(rstSurveyValues![Condition Grades]))
>         Dim clsCondition As New classCondition
>         clsCondition.ID =3D rstSurveyValues.Fields("IDValues").Value
>         clsCondition.Grade =3D 
> rstSurveyValues.Fields("Condition Grade Abbr= ev").Value
>         colConditionGrades.Add clsCondition
>         Set clsCondition =3D Nothing
>         rstSurveyValues.MoveNext
>     Loop
> End Sub
> 
> The run-time error message says that the object has not been 
> set and breaks=  on the line=20
>         colConditionGrades.Add clsCondition
> 
> VBA has allowed me to make calls to clsConstruction to give 
> values to the p= roperties, but suddenly it says that the 
> object has not been set.
> 
> If I right mouse click on the classConstruction in the Dim 
> statement and as= k to be shown the definition the error is 
> given saying VBA can not find a d= efinition.  However the 
> object classConstruction appears in the object brow= ser and 
> the dim statement has been executed.
> 
> I have set Option Explicit at the start of all modules.
> 
> Any ideas what I am doing wrong? and how can I get this working.
> 
> Most frustrating is that I have copied the code from 
> something that does wo= rk!
> 
> Thanks in advance,
> 
> Alan.
> 
>

*************************************************************
You are receiving this mail because you subscribed to mso@xxxxxxxxxxxxx or 
MicrosoftOffice@xxxxxxxxxxxxxxxx

To send mail to the group, simply address it to mso@xxxxxxxxxxxxx

To Unsubscribe from this group, send an email to 
mso-request@xxxxxxxxxxxxx?Subject=unsubscribe

Or, visit the group's homepage and use the dropdown menu.  This will also allow 
you to change your email settings to digest or vacation (no mail).
//www.freelists.org/webpage/mso

To be able to use the files section for sharing files with the group, send a 
request to mso-moderators@xxxxxxxxxxxxx and you will be sent an invitation with 
instructions.  Once you are a member of the files group, you can go here to 
upload/download files:
http://www.smartgroups.com/vault/msofiles
*************************************************************

Other related posts: