Well, I am stuck again.

Posted on 2005-04-18
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
    LVL 6

    Accepted Solution

    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)

    LVL 3

    Author Comment

    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.
    LVL 3

    Author Comment

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

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    IT, Stop Being Called Into Every Meeting

    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!

    Suggested Solutions

    Introduction This article makes the case for using two modules in your VBA/VB6 applications to provide both case-sensitive and case-insensitive text comparison operations.  Recently, I solved an EE question using the LIKE function.  In order for th…
    Article by: Martin
    Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
    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…

    794 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

    18 Experts available now in Live!

    Get 1:1 Help Now