Results 1 to 3 of 3

Thread: Binding fields/recordset/database to a class module

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    May 2000
    Location
    Mexico City
    Posts
    242

    Question

    I'm writing several class modules to access a database.

    My question is, How can I bind a module instance (element of a collection) to a certain record in an open db?

    Suppose I have a collection class called Employees, that holds Employee classes. Now, if I modify a property in the class Employee, or if I add a new entry using the Add method of the collection Employees, how do I update/add the record in the database?

    I'm currently using the following approach:

    ' Example snippet from the Employee class
    Public Property Let RFC(NewValue As String)

    msRFC = NewValue
    grsEmployees.Find msRFC
    grsEmployees.Fields("RFC") = msRFC

    End Property

    Notes:
    - msRFC is privately declared as a "String" in the Employee class/module
    - grsEmployees is a globally declared recordset in a standard module
    - RFC is unique to each employee

    Now, I'm sure there has to be a different approach...I just haven't found it.

    Maybe with the DataBindingBehavior property? If so, How?

    Thanks in advance!

  2. #2
    Fanatic Member
    Join Date
    Oct 1999
    Location
    England
    Posts
    982

    Post

    Looking in MSDN the description of the DAtaBindingsBehaviour is as follows:

    Use the DataBindingBehavior property when you want an object to act as a consumer of data provided by objects. A data consumer may be either simple bound (binding to single fields) or complex bound (binding to a rowset).

    When DataBindingBehavior is set to 1 (vbSimpleBound), the PropertyChanged event and the CanPropertyChange method are added to the object's procedures.
    When complex bound is selected the following properties are added to your module allowing you to add the relevant code to set the DataSource and DataMember.

    Code:
    Public Property Get DataSource() As DataSource
    
    End Property
    
    Public Property Set DataSource(ByVal objDataSource As DataSource)
    
    End Property
    
    Public Property Get DataMember() As DataMember
    
    End Property
    
    Public Property Let DataMember(ByVal DataMember As DataMember)
    
    End Property
    A data provider can have multiple datasets that a consumer can choose to bind to. Each is called a "data member," and is identified by a unique string.

    For example, when using a Data Environment that contains several Command objects as a DataSource, the DataMember specifies which Command object to use.

    Hope all this helps in some way.


    Things I do when I am bored: DotNetable

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    May 2000
    Location
    Mexico City
    Posts
    242
    deja vu... I'm sure I read that somewhere before... Anyway, as I write this, I haven't already tested your solution, but I'm sure it'll work the way I want.

    thanks a lot!

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