Wrox Home  
Search P2P Archive for: Go

  Return to Index  

access thread: Where to set dirty property on form?


Message #1 by "Darin Marsh" <netadmin@l...> on Wed, 12 Mar 2003 19:38:05
I have a form with just a few fields on it.  All of them have default 
values, however if the user wants to accept these default values without 
changing anything and clicks ok to close the form, the data doesn't save.  
The form works fine if something gets changed, its just when defaults are 
accepted that it fails.  I've tried doing a Me.Dirty = True in the open 
event of the form and in the onclicked of the ok button, niether work.  
Any help is much appreciated.

Darin
Message #2 by "Charlie Goodwin" <cgoodwin@c...> on Wed, 12 Mar 2003 15:43:55 -0500
Darin,

The dirty "property " is actually an "event" that occurs
when the user makes a change in a record. So, you
cannot set it...you can use it but the only way to
"set" it is to modify a record.

At least in recent versions of Access you can see it.
If you look at the form in design view, and open up
the properties window, click on "Event" and you
should see an event named On Dirty. But I don't think
you will have to use that event to get where you want
to go.

In your case, simply going to the "new record", i.e.
kinda just visiting...then going back away from it will
not trigger the On dirty event.   Access assumes there
is nothing to save, and just leaves all as it was before
you visited the new record.   You need to make a
change while you're there...almost any change.
Once you do, then Access will recognise that a new
set of data should be recorded and should add your
new record to the list of existing records.

If you can work with changing the design of your form...
here's a solution.



First change one field's default value.  Simply remove
your existing default setting.   Lets say that  in a Textbox
you have named "TxtYourTextBoxName" you have
default to "Bob".   Just delete "Bob".

Add a button to your form.

Name your button something like     "BtnDefNew"
Set it's Caption Property to: "Make new default record"

On it's On Click event, build code:


'Code to create default record follows

	Private Sub BtnDefNew_Click()

		'Move the form to the new record
	DoCmd.GoToRecord , "FrmYourFormName", acNewRec
		'Substitute your form's name for FrmYourFormName

		'Change a value so your form "sees"
		' new data and will actually save it
	TxtYourTextBoxName = "Bob"  '
		'Substitute your control's name for   TxtYourTextBoxName
		'Substiute the default setting you want for "Bob"

	End Sub

When you click that button, your form should go to a new
record and put a new value into TxtYourTextBoxName. Access
will see new data and add the newly created record to your
table.   You don't need to explicitly use the "On Dirty" event,
but by making a change...Access will do the new record
saving you want.

After the new record is really created by the action of setting
a firld to "Bob" or whatever, You can modify anything else if
you want.

Let us know how it goes.

Charlie







> I have a form with just a few fields on it.  All of them have default
> values, however if the user wants to accept these default values without
> changing anything and clicks ok to close the form, the data doesn't save.
> The form works fine if something gets changed, its just when defaults are
> accepted that it fails.  I've tried doing a Me.Dirty = True in the open
> event of the form and in the onclicked of the ok button, niether work.
> Any help is much appreciated.
>
> Darin.

  Return to Index