By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,301 Members | 1,766 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,301 IT Pros & Developers. It's quick & easy.

How to not trigger dirty event when initializing control on form through VB?

P: n/a
P
Hi,

I have a form with several controls. One of them is initialized through VB
in frm_current. I am using the frm_beforeupdate event to prompt users for
saving changes. How can I make it so that the initialization of the control
does not dirty the form? I don't want to prompt the users for saving changes
unless he changed one of the remaing controls on the form. BTW, the control
I initialize is a foreign key and changes over time. Thank you. P
Nov 12 '05 #1
Share this Question
Share on Google+
6 Replies


P: n/a
"P" <P@no_spam.com> wrote in message
news:v5*********************@newssrv26.news.prodig y.com...
Hi,

I have a form with several controls. One of them is initialized through VB
in frm_current. I am using the frm_beforeupdate event to prompt users for
saving changes. How can I make it so that the initialization of the control
does not dirty the form? I don't want to prompt the users for saving changes
unless he changed one of the remaing controls on the form. BTW, the control
I initialize is a foreign key and changes over time. Thank you. P


You can't unless you can set the control's default value property instead. As
long as you set the Value property the record will be dirtied. You could also
wait until the BeforeUpdate event to make the assignment instead of using
Current.
--
I don't check the Email account attached
to this message. Send instead to...
RBrandt at Hunter dot com
Nov 12 '05 #2

P: n/a
P
Thank Rick for your suggestion. I set the control's default value property
in frm_load and that takes care of the issue. However, I have on the same
form a subform listing all current record for that foreign key. I run a
requery of the subform in frm_current. Although the combo box now shows the
default value, the subform no longer lists the associated records when the
main form is in New-Rec mode. It looks like the master field for the subform
does not longer hold the key value when in New-Rec mode although the combo
box shows the value. Any thoughts? Thank you. P
"Rick Brandt" <ri*********@hotmail.com> wrote in message
news:br*************@ID-98015.news.uni-berlin.de...
"P" <P@no_spam.com> wrote in message
news:v5*********************@newssrv26.news.prodig y.com...
Hi,

I have a form with several controls. One of them is initialized through VB in frm_current. I am using the frm_beforeupdate event to prompt users for saving changes. How can I make it so that the initialization of the control does not dirty the form? I don't want to prompt the users for saving changes unless he changed one of the remaing controls on the form. BTW, the control I initialize is a foreign key and changes over time. Thank you. P
You can't unless you can set the control's default value property instead.

As long as you set the Value property the record will be dirtied. You could also wait until the BeforeUpdate event to make the assignment instead of using
Current.
--
I don't check the Email account attached
to this message. Send instead to...
RBrandt at Hunter dot com

Nov 12 '05 #3

P: n/a
Right after you update the field in code, do a

me.Refresh

The above will force a disk writge, and thus dirty = false.
--
Albert D. Kallal (MVP)
Edmonton, Alberta Canada
No************@msn.com
http://www.attcanada.net/~kallal.msn
Nov 12 '05 #4

P: n/a
P
Thank you Albert. I tried me.refresh but it did not work.
The form is bound to a table with a two-field key (many-to-many table). I
set one part of the key (AccountKey) by setting its default value when I
load the form. The form also contains a subform which has its master field
set to the same key field (AccountKey). When I go to a new record (I use
docmd.GoToRecord acForm, frm.name, record:=acNewRec), I can see the value
set for AccountKey but the subform is empty until I save the record. Any
thoughts? P
"Albert D. Kallal" <pl********************@msn.com> wrote in message
news:KtbBb.616577$9l5.300438@pd7tw2no...
Right after you update the field in code, do a

me.Refresh

The above will force a disk writge, and thus dirty = false.
--
Albert D. Kallal (MVP)
Edmonton, Alberta Canada
No************@msn.com
http://www.attcanada.net/~kallal.msn

Nov 12 '05 #5

P: n/a
I don't understand the problem that the sub-form is empty?

I mean, there is no need/reason to add sub-form records until the user
edits, or needs one?

Virtually 90% of all my quires are left joins. A left join means that
records will appear in reports EVEN if a child record is not present when
doing a join.

Also, when you state that you are moving to a new record, are you talking
about the main form, or the sub-form?

I also don't see why the fact that the sub-form is empty is a problem? You
should not be adding sub-records until the user actually edits the sub-form.
And, in fact, when the cursor moves to the sub-form, the main form is
written to disk anyway for you. (thus, you probably don't need my me.refresh
idea anyway).

Are you trying to add a sub-form/child record from code in the main form?
(and do you *really* need/want to do this?. As mentioned, there is NO REASON
to create these child record needlessly...is there?).

There is no question that you MUST FIRST write out the main record BEFORE
you attempt to add, or edit a child record. Your code that sets the default
key should do the trick here, and that should cause the main record to be
dirtied. At that point, you are free to add/edit child records...but
certainly no child records should exist until the main record is edited (and
further, as mentioned, NO CHILD records need to be added until the user
actually edits the sub-form).

In addtion, you are talking about a form-load event, and then you are
talking about a commadn to move to a new reocrd. When you move to a new
record, the form load event is not triggered. Perahps you need to add the
"set default" code to the buttion that moves to a new record?

--
Albert D. Kallal (MVP)
Edmonton, Alberta Canada
No************@msn.com
http://www.attcanada.net/~kallal.msn
Nov 12 '05 #6

P: n/a
Hum, in reading your original question, you problem is not one of "ditry",
but one of setting the default record id, and NOT triggering the before
update event. I kind of miss-read what your actual probelm is. (it is not
one of adding the child reocrd, but simply that the "before updat" even is
trigged.

I would suggest that you actaully add the reocrd first, and then load the
form "to" that record.

The code to "add" the new record could be:

Dim lngPos As Long

Me.RecordsetClone.AddNew
lngPos = YouNextIDFunction()
Me.RecordsetClone!ID = lngPos
Me.RecordsetClone.Update

Me.Bookmark = Me.RecordsetClone.LastModified

Me.Somefield.SetFocus
The above adds the record in code, and NOT via the form. You then "move" the
form to the record.
--
Albert D. Kallal (MVP)
Edmonton, Alberta Canada
No************@msn.com
http://www.attcanada.net/~kallal.msn
Nov 12 '05 #7

This discussion thread is closed

Replies have been disabled for this discussion.