Results 1 to 7 of 7

Thread: Calling Subprocedure problem

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Jun 2005
    Posts
    243

    Calling Subprocedure problem

    I created a class module to place a section of code in. The code reads the database and fills in a combobox with the records returned. I call the sub procedure from my form code by "Call mySP.FillSpecialPrograms", but the code hangs when it gets to the cboSpecProgs.Clear line. I receive a Run-time Error '424' Object required.

    Any suggestions??
    Here is the code for the sub procedure.


    Public Sub FillSpecialPrograms()
    Dim rs As New ADODB.Recordset
    rs.Open "select * from regtb_specialprog", gcnData

    cboSpecProgs.Clear <------This is where the code hangs.
    cboSpecProgs.AddItem ""

    cboSpecProgs.AddItem "Gifted/Talented"
    cboSpecProgs.ItemData(cboSpecProgs.NewIndex) = -1

    Do While Not rs.EOF
    cboSpecProgs.AddItem rs("description")
    cboSpecProgs.ItemData(cboSpecProgs.NewIndex) = rs("code")
    rs.MoveNext
    Loop

    rs.Close
    Set rs = Nothing

    End Sub

  2. #2
    PowerPoster Pasvorto's Avatar
    Join Date
    Oct 2002
    Location
    Minnesota, USA
    Posts
    2,951

    Re: Calling Subprocedure problem

    I would assume that you need the form name added to the item description.

    frmname.cboSpecProgs.Clear

  3. #3
    Frenzied Member David.Poundall's Avatar
    Join Date
    Sep 2002
    Location
    Robin Hood Land
    Posts
    1,457

    Re: Calling Subprocedure problem

    Basically cboSpecProgs has not been instantiated yet (as far as this procedure is concerned).
    David

    Learn the Rules so that you know how to break them properly.

    Printing dll dBTools MZTools Winsock API WinsockVB More Winsock SGrid2 MSChart Mail2Web

    If you have found this thread useful then read this

  4. #4
    Next Of Kin baja_yu's Avatar
    Join Date
    Aug 2002
    Location
    /dev/root
    Posts
    5,989

    Re: Calling Subprocedure problem

    On what line do you get the error? Did you try Stepping line by line to see what the problem might be?

  5. #5
    Addicted Member
    Join Date
    May 2005
    Posts
    168

    Re: Calling Subprocedure problem

    Hi,

    zombie:

    You need to pass the combobox to your class method so your sub declaration looks like:

    Public Sub FillSpecialPrograms(ByVal cboSpecProgs As ComboBox)

    and calling it:

    obj.FillSpecialPrograms cboSpecProgs

    Have a good one!
    BK

  6. #6

    Thread Starter
    Addicted Member
    Join Date
    Jun 2005
    Posts
    243

    Re: Calling Subprocedure problem

    Thanks Pasvorto. That was the problem.

  7. #7

    Thread Starter
    Addicted Member
    Join Date
    Jun 2005
    Posts
    243

    Resolved Re: Calling Subprocedure problem

    resolved
    Last edited by zombie_man23; Jun 20th, 2005 at 03:37 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width