Well, I am stuck again.

Posted on 2005-04-18
Medium Priority
Last Modified: 2010-05-02
I previously received help on problems with my class/methods.
Now, I am having problems with my colllection code.

I am copying this code, through a step-by-step tutorial, from an Advanced VB book.

I receive the error, "Method or data member not found" on the mDispensaryItems.Add listed below.

Private Sub cmdAdd_Click()
    'Add an item to the collection
    If cboFrameSize.ListIndex <> -1 And cboFrameStyle.ListIndex <> -1 Then
        mDispensaryItems.Add cboFrameStyle.ListIndex + 1, cboFrameSize.ListIndex + 1, Val(txtQuantity.Text)
        MsgBox "Enter values for the item.", vbInformation, "Dispensary Items"
    End If
    cmdClear_Click  'clear out form controls
End Sub

Can someone help me identify where I went wrong?  I am sure it is something I left out, but as I am teaching myself, I do not really know where to go from here.
Question by:shawngilbert
  • 2

Accepted Solution

GPrentice00 earned 1200 total points
ID: 13810870
double-check your class.  The error is suggesting that there is no method ".Add" that it can use.
Primary cause:  You haven't put it in the class yet
Secondary cause:  You made it private rather than public in the class.

(If the .Add appears in the Intellitext as you type in the editor, thats good, and yeah, it is exposed, so then the error would be within the code in the class itself, a typo perhaps there too.  If .Add does NOT appear in the intellitext as you type, but other methods/properties do, its definitely because either it doesn't exist, or its not exposed in the class)


Author Comment

ID: 13810923
I have my main form, a cDispensaryItem 'class' and a cDispensaryItems 'collection'.  I do not have an Add method in the 'class', nor was one printed for it in the book.

In my collection, I have

Private mDispensaryItems As Collection

and I have

Private Sub Add(ByVal intFrameStyle As Integer, ByVal intFrameSize As Integer, ByVal intQuantity As Integer)

But in my form's code, if I type mDispensaryItems. it only displays Count, Item, NewEnum and Remove as options.

I am trying to learn classes and collections, but finding it very difficult.

Author Comment

ID: 13810929
Oh dear.  You are correct.
I reread it and my Add method WAS declared as Private.
Thank you so very much!

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
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…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses
Course of the Month12 days, 17 hours left to enroll

578 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