Dirty property & Changing values via VB

R

Rob Hofkens

Hello people :)

Whenever you change data on a form via keyboard the Dirty property responce
to that.
It's possible to perform actions via the Form_Dirty sub after this.
But when I change field values via VB then this system doesn't work anymore.

A sample :

A table holds some numeric code.
Everytime the user adds a new record he needs to add a new unique code.
To make things simple I generate a code for him and present it in a dialog
window.
When he accepts the new code I simply do : Me!
Code:
 = strCode.
This however doesn't trigger the Dirty event/property ?

Since I want to create some sub's that count on the Dirty system I have to
rethink this now.

Any help in this matter would be apreciated.

Thanx in advance,

Rob.
 
D

Douglas J. Steele

You sure about that?

I just tried the following code:

Private Sub Command4_Click()
Debug.Print "Me.Dirty = " & Me.Dirty
Me.AttributeNm = Me.Text2
Debug.Print "Me.Dirty = " & Me.Dirty
End Sub

and got the following in the Immediate window:

Me.Dirty = False
Me.Dirty = True
 
G

George Nicholson

If Me!
Code:
  refers to a Field in the underlying recordset (and not a
controlname on the form) then no, it won't trigger the Form's Dirty
event/property since you aren't directly changing the form, you're changing
the data which will be displayed on the form. A small but important
distinction.

If you change the value of a control on the form (Me.txtCode = MyValue),
then the form should become Dirty.

Of course, you could always add a "Me.Dirty = True" statement if you need to
force the issue.

HTH
 
R

Rob Hofkens

Oh, my bad.
I relied to much on the Form_Dirty() sub and presumed that if that wasn't
triggered then the Dirty property wasn't set too.
Your sample code shows that the Dirty property is set even though the
Form_Dirty() sub isn't triggered.
I think I just need to trigger the sub myself after I change a fields value
by VB to solve my problem.

Thank you Douglas !

Rob.

Douglas J. Steele said:
You sure about that?

I just tried the following code:

Private Sub Command4_Click()
Debug.Print "Me.Dirty = " & Me.Dirty
Me.AttributeNm = Me.Text2
Debug.Print "Me.Dirty = " & Me.Dirty
End Sub

and got the following in the Immediate window:

Me.Dirty = False
Me.Dirty = True


--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


Rob Hofkens said:
Hello people :)

Whenever you change data on a form via keyboard the Dirty property
responce to that.
It's possible to perform actions via the Form_Dirty sub after this.
But when I change field values via VB then this system doesn't work
anymore.

A sample :

A table holds some numeric code.
Everytime the user adds a new record he needs to add a new unique code.
To make things simple I generate a code for him and present it in a
dialog window.
When he accepts the new code I simply do : Me!
Code:
 = strCode.
This however doesn't trigger the Dirty event/property ?

Since I want to create some sub's that count on the Dirty system I have
to rethink this now.

Any help in this matter would be apreciated.

Thanx in advance,

Rob.
[/QUOTE]
[/QUOTE]
 
R

Rob Hofkens

I see, I presumed that Dirty property was read only...I am going to check
this out some more.

Thank you George !

Rob.

George Nicholson said:
If Me!
Code:
  refers to a Field in the underlying recordset (and not a
controlname on the form) then no, it won't trigger the Form's Dirty
event/property since you aren't directly changing the form, you're
changing the data which will be displayed on the form. A small but
important distinction.

If you change the value of a control on the form (Me.txtCode = MyValue),
then the form should become Dirty.

Of course, you could always add a "Me.Dirty = True" statement if you need
to force the issue.

HTH


[QUOTE="Rob Hofkens"]
Hello people :)

Whenever you change data on a form via keyboard the Dirty property
responce to that.
It's possible to perform actions via the Form_Dirty sub after this.
But when I change field values via VB then this system doesn't work
anymore.

A sample :

A table holds some numeric code.
Everytime the user adds a new record he needs to add a new unique code.
To make things simple I generate a code for him and present it in a
dialog window.
When he accepts the new code I simply do : Me![Code] = strCode.
This however doesn't trigger the Dirty event/property ?

Since I want to create some sub's that count on the Dirty system I have
to rethink this now.

Any help in this matter would be apreciated.

Thanx in advance,

Rob.
[/QUOTE]
[/QUOTE]
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top