Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

On Dirty Event for Details only

Status
Not open for further replies.

TechieJr

Instructor
Nov 13, 2002
71
CA
Hi all,

I have a field on a form which shows who updated the selected record last. The field is updated using code behind the form's "On Dirty" event. My problem is that I want the code to execute only when a control in the Detail section of the form is changed. There are controls in the Header section of the form which are triggering the code execution when they should not. In a nutshell, I need an "On Dirty" event for the Detail section of the form only. Any suggestions?

Thanks,
Techie Jr.
 
Hi Techie Jr :),

What I do is create my own 'Dirty' property, and link it only to the controls I want.

Firstly, you need a variable to store the state, in the general declarations of your module:

Code:
Private blnDirty as Boolean

Then the property procedures:
Code:
Public Property Get DirtyDetail() As Boolean
    DirtyDetail = blnDirty
End Property

Private Property Let DirtyDetail(blnAmIDirty As Boolean)
    blnDirty = blnAmIDirty
End Property

Then, select each control in the detail section that you want to use the Dirty property, (using ctrl-click or dragging). I used to create AfterUpdate procedures for each control, but I have just thought of a easier way to hook them into the property and that is to just use another function to set the state. So, with every control selected, in the AfterUpdate box on the property sheet, type: =MakeMeDirty(True).

Finally, add this function and you're away.
Code:
Private Function MakeMeDirty(blnState As Boolean)
    DirtyDetail = blnState
End Function

The good thing about property procedures is you can add any other functionality you want to occur when the property is changed. For example, you could have a Save button that is disabled until the user has made changes and at the end of the Property Let procedure have the line:

Code:
cmdSave.Enabled = DirtyDetail

Just make sure you always set the actual property as opposed to the private variable. So:
Code:
DirtyDetail=True
, not:
Code:
blnDirty=True
.

Hope that is of some use.

Dean :)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top