HELP I need a little help...

Man...I'm trying to learn class modules and multitier database applications...
So I just finished typing in like 30 pages of code (the sample project from my training manual).
I was going to step through it so I could watch the whole boring process....
Well, it errors out immediately on one of my modules with this error:

User-defined type not defined.

This is within my CPatient module on a property:

Public Property Get Insurance() As DataSource
    'Expose the data source to bind to the DataCombo box
    Set Insurance = mDataService
End Property

Can someone tell me where to begin to look for the answer?  It's got to be a type-o on my part since I copied it out of the book...(I hope :(
LVL 67
Who is Participating?
David LeeConnect With a Mentor Commented:
1.  If DataSource is a user defined type, then it must be declared somewhere.  You should be able to find something like:

Type DataSource
End Type

2.  Based on the line of code "Set Insurance = mDataService", yes, Insurance is an object.  But it's possible that the object declaration is missing and that's causing the problem.

My guess is that DataSource is defined as a type.  Consider this code fragment.

Private Sub Command1_Click()
    Dim varTest As Testing
End Sub

If you create a new project, drop this code into it, be sure to add a command button called Command1, and step through it you should get the same error you're reporting.  Since the only data type I see in the code you indicate as generating the error is DataSource, I have to suspect that it isn't defined (i.e. there is no type declaration).  A simple test to see if that's the case would be to create a type declaration for it and see if the error goes away.  If it does, then that's the problem.  Solving it is more of a problem unless you can discover what the proper type declaration is supposed to be.  If that doesn't make the error go away, then my guess is wrong.
David LeeCommented:
I'd check two things.

1.  Is there a DataSource type declared somewhere?
2.  Is Insurance an object?
Ryan9999Connect With a Mentor Commented:
i would look at mDataService and see if it is either out of scope or spelled wrong
Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

sirbountyAuthor Commented:
>>1.  Is there a DataSource type declared somewhere?<<
What would I be looking for?

>>2.  Is Insurance an object?<<
Doesn't the property above indicate that it is?  (that's sounds a bit sarcastic, but it's not, I assure you)

>>i would look at mDataService and see if it is either out of scope or spelled wrong<<
I searched for all instances of mData and all came up with Service spelled correctly.

I did find a couple of instances of CDataService, mistyped as CDataSource - but that didn't change anything...:(
sirbountyAuthor Commented:
Nope - there's no Type DataSource anywhere...

Here's the head of the CPatient module...

Option Explicit

'Create an instance of the Data Services Class
Private mDataService As CDataService

'Declare a BindingCollection to bind data source and data consumer
Private mbndPatient As BindingCollection

'Declare properties for Patient (Note alphabetic order)
Private mstrCity As String
Private mstrFirstName As String
Private mstrInsuranceCompanyCode As String
Private mstrLastName As String
Private mintPatientNumber As Integer
Private mstrPhone As String
Private mstrPolicyNumber As String
Private mstrState As String
Private mstrStreet As String
Private mstrZipCode As String

'Enum for error code
Public Enum paError
    paValidationError = vbObjectError + 512 + 100
End Enum

'******Property Procedures*******

Public Property Get Insurance() As DataSource
    'Expose the data source to bind to the DataCombo box
    Set Insurance = mDataService
End Property

I added

Private Type DataSource
End Type

but get an error on that ..."User defined type without members not allowed"

I can't imagine this not being in the code though if it is needed.  I copied this strait from the text.  I could imagine a type-o, but not missing a section like this.
Could be that the text is just wrong, I suppose (sure is a lot of wasted time for me typing it all in though >:(

I've bumped the points some... I'd really like to get this working so I can begin to have a better understanding here.

Thanx for all your help so far.
David LeeCommented:
Yes, the Type declaration needs at least one member.  Sorry, I just used Type, End Type as an example.  Try adding this and see if that clears the problem up.

Private Type DataSource
   varData as Variant
End Type

I agree that it seems unlikely that a required Type declaration would be missing from the sample program text.  But I've seen things like that happen.  I'm probably wrong and it's something else, but the error message points in this direction so I'm just trying to be methodic and eliminate it as a possibility.
sirbountyAuthor Commented:
...and I DO appreciate you're helping me here.

Okay - with that addition, I'm now getting the following:

Compile Error:
Private Enum and user defined types cannot be used as parameters or return types for public procedures, public data members, or fields of public user-defined types.

And it's flagging my Insurance property again.. :(
sirbountyAuthor Commented:
Hmm - one other thing before the code in the manual.
Add references to your project for MS Data Binding Collection, which I did and the MS Active X Data Object 6.0 Library.
Mine only goes as high as 2.7, so I assumed this was a type-o referencing 2.6?
sirbountyAuthor Commented:
Doh! I removed ADO 2.6 and added 2.7 and I get as far as Form_Load finally... :D
sirbountyAuthor Commented:
Private Sub Form_Load()
    'Set up the form controls to handle data
    Set mPatient = New CPatient
    With dbcInsurance       'Bind DataCombo to data source
        .DataMember = "Patient"
        Set .DataSource = mPatient.Insurance
        .rowMember = "Insurance"                       '<-----------This is where it stops though.  Method or data member not found
        Set .RowSource = mPatient.Insurance
        .ListField = "Name"
    End With
    mnuSortPatientNumber_Click  'Set initial sort order & display data
End Sub
David LeeCommented:
That's progress.

The online help in VB6 describes the .RowMember property like this:

The RowMember property is equivalent to the DataMember property, and is used to fully qualify which set of data to bind to. When a data source supplies more than one data member, you must specify which to use before setting the DataField property.

I don't know what is meant by "equivalent to the DataMamber property".  It could mean that the value RowMember is set to must be the same value DataMember is set to.  Whatever it means though it seems clear that the program isn't finding a RowMember named Insurance.  You could try setting RowMember to Patient, the same value used in DataMember.  I'd also propose looking at the data source to see if it contains anything called Insurance.  The best way I can think of to do that is to open the data source and look at its properties.
sirbountyAuthor Commented:
Sorry for the delay - on the form, I have a dbCombo, dbcInsurance.
It's properties do not list a rowmember, only a rowsource - so I'm wondering if I chose the wrong control....
Ever hear of ADO 6.0?  That one still confuses me...
sirbountyAuthor Commented:
Oh well, I think I've given up...
I'll move on to the next chapter and hopefully get something from it there.
Thanx for the help though..
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.