adam_r_davis
01-20-2007, 06:12 PM
Hello,
I have had a small DB that has grown non stop for several years and the cracks are getting bigger. I now want to start coding in a more elegant fashion, but am having trouble finding examples to work from.
Goal1: Use class modules to get sensible functions like ThsiPerson.MergeDuplicatePerson(iOtherPersonID)
Goal2: Use a DirtyData table to avoid data clashes and Access' horrible "Do you want to drop changes" functionality replacing it with "JoeBloggs is currently editing this person's details"... Retry / Cancel.
Solution to date:
1: Create a class module clsPerson with various methods like Load and Save. ThisPerson.Load writes a "Reader" lock to a table "tRowLocks" and the various Let properties write a "Writer" lock to the same table. The ThisPerson.Save method clears the locks etc.
2: Create a form fmPerson that has a data source of "Select PersonID from tPeople" so there are no fields on the form that are bound, Equally a listbox could do the trick of supplying a PersonID, but either way I don't want to use the Access data binding.
Problem: I want to create an instance of my clsPerson when I open the form, load it based on Me.RecordSet!PersonID and have it persist until the form.OnCurrent or close events fire and then do a SaveChanges type process. That is, if the Surname or whatever is loaded up and the user edits it, I would like to just say:
Option Compare Database
Dim ThisPerson As New clsPerson
Private Sub Form_Current()
ThisPerson.Load (Me.Recordset!PersonID)
End Sub
...
private sub txtSurname_Update()
ThisPerson.Surname = txtSurname
end sub
'...etc
But of course ThisPerson is always nothing, forcing me to do:
private sub txtSurname_Update()
ThisPerson.Load
ThisPerson.Surname = txtSurname
end sub
Because I am forced to load on every field change, the locking process fires more often than nessesary, wasting time and leaves me with a data sync problem because firstname may have also been edited, so I have to loop through every control in case they were changed on the form in the event before the current event.
This defeats the purpose of using a class module in the first place...??!!?@?@? So I clearly have no idea to use a class module with the form...
Question: How can I have an instance of the object ThisPerson that remains loaded throughout the life of the form, or is there a different way of managing the data while still using class modules?
Thanks in advance for any help
Adam
I have had a small DB that has grown non stop for several years and the cracks are getting bigger. I now want to start coding in a more elegant fashion, but am having trouble finding examples to work from.
Goal1: Use class modules to get sensible functions like ThsiPerson.MergeDuplicatePerson(iOtherPersonID)
Goal2: Use a DirtyData table to avoid data clashes and Access' horrible "Do you want to drop changes" functionality replacing it with "JoeBloggs is currently editing this person's details"... Retry / Cancel.
Solution to date:
1: Create a class module clsPerson with various methods like Load and Save. ThisPerson.Load writes a "Reader" lock to a table "tRowLocks" and the various Let properties write a "Writer" lock to the same table. The ThisPerson.Save method clears the locks etc.
2: Create a form fmPerson that has a data source of "Select PersonID from tPeople" so there are no fields on the form that are bound, Equally a listbox could do the trick of supplying a PersonID, but either way I don't want to use the Access data binding.
Problem: I want to create an instance of my clsPerson when I open the form, load it based on Me.RecordSet!PersonID and have it persist until the form.OnCurrent or close events fire and then do a SaveChanges type process. That is, if the Surname or whatever is loaded up and the user edits it, I would like to just say:
Option Compare Database
Dim ThisPerson As New clsPerson
Private Sub Form_Current()
ThisPerson.Load (Me.Recordset!PersonID)
End Sub
...
private sub txtSurname_Update()
ThisPerson.Surname = txtSurname
end sub
'...etc
But of course ThisPerson is always nothing, forcing me to do:
private sub txtSurname_Update()
ThisPerson.Load
ThisPerson.Surname = txtSurname
end sub
Because I am forced to load on every field change, the locking process fires more often than nessesary, wasting time and leaves me with a data sync problem because firstname may have also been edited, so I have to loop through every control in case they were changed on the form in the event before the current event.
This defeats the purpose of using a class module in the first place...??!!?@?@? So I clearly have no idea to use a class module with the form...
Question: How can I have an instance of the object ThisPerson that remains loaded throughout the life of the form, or is there a different way of managing the data while still using class modules?
Thanks in advance for any help
Adam