473,471 Members | 1,937 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

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

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
6 3031
"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
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
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
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

15
by: Rey | last post by:
Howdy all. Appreciate your help with several problems I'm having: I'm trying to determine if the Visit subform (subformVisits) has a new record or been changed, i.e. dirty. The form that...
2
by: Salad | last post by:
A97. I have a command button to save and exit. I had the code If Me.Dirty Then Docmd.RunCommand acCmdSaveRecord ...more code endif I was getting an error because a value was not getting...
9
by: Susan Bricker | last post by:
I am currently using the OnDirty event of a Form to detect whether any fields have been modified. I set a boolean variable. Then, if the Close button is clicked before the Save button, I can put...
5
by: Dave | last post by:
How do I check in a Windows Forms app if any controls have changed? I have a form that collects data, and I want to prompt the user if they try to exit the app, or load a new file, without saving...
5
by: Alain Filiatrault | last post by:
Hi, I need to implement a "form.dirty" feature on a VB .NET form not related to a database. I need to know if any of the items (Textboxes, combo, listboxes, ...) was changed. Is there a quick...
2
by: Franky | last post by:
Threre is a Form containing a usercontrol In the form's Load event it references a usercontrol property, say, zz The first showdialog(formx) causes 1 usercontrol_load event 2 form_load event...
2
by: Alan Mailer | last post by:
Ok, I'm pretty new to VB.Net, so please bear with me. Imagine the Load event of one of my forms includes the following: Dim ctrl as Control Dim txtbox As TextBox For Each ctrl In Me.Controls...
1
Ericks
by: Ericks | last post by:
I have a subform that contains several controls of which one is a date control called “DateOfInfoAdded”. The default format of this control is date() so whenever a new record is created the date is...
6
by: Mark B | last post by:
I have a function that looks up a SQL table to see if a search term matches. It works fine but so far there are two things yet to work: 1) After entering a search term and pressing Enter, nothing...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.