Results 1 to 4 of 4
  1. #1
    Join Date
    Feb 2006
    Posts
    46

    Unanswered: Creating and Invoking a custom class/object

    I am trying to create a class in VBA. I am wondering why I cannot get it to work. I have created a VBA class module and I have some code in. When I declare it within a Form load event, I cannot get it to work. My code is below and I am getting an error that states "Compile Error: Definitions of property procedures are inconsistent, or property procedure has an optional parameter, a ParamArray, or an invalid Set Final Parameter.

    'My Declararation is as follows:

    Private Sub Form_Load()
    Dim myClass As clsRecordset
    Set myClass = New clsRecordset
    myClass.TableName = "THIS IS A TEST"
    End Sub




    'MY CLASS IS DECLARED AS FOLLOWS:
    Option Explicit
    Option Compare Database

    Public Property Get DataSource() As String

    End Property

    Public Property Set DataSource(strDataBaseName As String)

    End Property

    Public Property Get TableName() As String

    End Property

    Public Property Set TableName(strTableName as string)
    TableName = strTableName
    End Property

    Public Property Set ConnectStatus(strStatus As String)

    End Property

    Public Property Set DataBaseType(strDBType As String)
    'Want Access, SQL Server, and Oracle,
    DataBaseType = strDBType
    End Property
    Public Sub ConnectDb()

    End Sub

  2. #2
    Join Date
    Feb 2004
    Location
    One Flump in One Place
    Posts
    14,912
    Hi Shiva65 - welcome to the forum

    Something more like:
    Code:
    'MY CLASS IS DECLARED AS FOLLOWS:
    Option Explicit
    Option Compare Database
     
    Private mTableName as String
     
    ...
     
    Public Property Set TableName(strTableName as string)
    mTableName = strTableName
    End Property
    Your property assignment should be to set the value of a private member variable (hence the m prefix)

    HTH
    Testimonial:
    pootle flump
    ur codings are working excelent.

  3. #3
    Join Date
    Mar 2003
    Location
    The Bottom of The Barrel
    Posts
    6,102
    Provided Answers: 1
    Try it like this:

    Private m_databasetype as String

    Public Property Get DatabaseType
    DatabaseType = m_databasetype
    End Property

    Public Property Let DataBaseType(strDBType As String)
    'Want Access, SQL Server, and Oracle,
    m_databasetype = strDBType
    End Property
    oh yeah... documentation... I have heard of that.

    *** What Do You Want In The MS Access Forum? ***

  4. #4
    Join Date
    Feb 2004
    Location
    One Flump in One Place
    Posts
    14,912
    Oops - Teddy spotted something I missed - pay attention to the Get, Set & Let distinction
    Testimonial:
    pootle flump
    ur codings are working excelent.

Posting Permissions

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