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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

User-friendly popup selection form doesn't fire main dirty event 2

Status
Not open for further replies.

Tarnish

Technical User
Nov 13, 2006
221
US
Hi all,

I've got a problem I can't figure out how to fix.

I use the Developer's Handbook code for form timeout, which basically calls a function when the form is dirty that starts a timer. If the record is saved/undone, the timer stops and will start again when the form_dirty event fires again.

The problem is there are two controls that can be modified on the form that aren't firing the form_dirty event. One is a text box that I use the datepicker form to fill with a date. The other is a text box that I use a 'TimePicker' form I created to fill with a time. The TimePicker requires no functions (like the DatePicker).

Question: Is it because the textboxes are filled via code that the form_dirty event isn't firing? If so, what can I do? If not, what's the problem?

PS: I tried writing some code for the 'on_change' event of the textbox, in which I was going to determine if the form was dirty and, if so, nothing, but if not, fire the lockout function. The 'on_change' event isn't fired by changing the date info in the textbox. I think I also tried the on_dirty event of the textbox as well....

Thanks, in advance,
T
 
Changing by code the Value of a control doesn't fires the form's Dirty event.
A workaround is to use the SetFocus method and change the Text property of the control.

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Thanks PH,

That worked fine for the TimePicker I think. Going to have to dig a little deeper to see if I can apply that principle to the datepicker....

Thanks again for the direction,
T
 
Another possibility might be to set the form's Dirty property to true in the same procedure that writes the new values.

Ken S.
 
Hiya Ken,

How goes it?

I tried to set the Form_Dirty property like that before I posted the question...heh, no luck.

I inching closer to an answer. I can just add code like this to the on_close event of the datepicker to get the timer to go off in the main form:

Forms!MyForm!myDateTextBox.SetFocus
Forms!MyForm!myDateTextBox.text = Forms!MyForm!myDateTextBox

Of course, that fires it off whether or not the datepicker was cancelled and even if the same date is used. I'm playing around with trying to read/set a variable at the form_open of the datepicker to record the 'starting' value for that textbox on the main form and then maybe compare the 'current' value on close to see if they match and then run the above code (or no code) accordingly. Haven't thought it all out just yet :)

Good to see ya,
T
 
Hiya, T,

Really? Me.Dirty = True wouldn't trigger the OnDirty code? Hmmm...

Likewise, good to see you too!

Ken S.
 
Ken,

I take that back. I can setfocus to the txtDueDate in the close event of the datepicker and then use:
Forms!MyForm.dirty = true

I still need a way to avoid calling it if the date isn't changed or the datepicker is cancelled...

T
 
Hmm... in my little informal test, changing the value of a control in code (via an InputBox) causes the form to become dirty, but doesn't fire the OnDirty event. How's that for a puzzler? And Me.Dirty = True didn't fire the OnDirty event either. However, calling the OnDirty sub DOES trigger the OnDirty event code:
Code:
Call Form_Dirty(0)
Have a look at the OldValue property of your control...

Ken S.
 
Ken,

I DID try calling that sub earlier, but it kept prompting me for a (?) which I didn't know. When I said in the last post that I could trigger the on_dirty event, I was saying from the datepicker on_close event using the setfocus back to the main and in the next line (still in the on_close of the datepicker) setting the forms!myform.dirty = true.

Anyway, I know I should be able to use that 'oldvalue' property to get this done...that's exactly what I was looking for but since using the datepicker doesn't seem to want to trigger any events, I'm not sure where I'd put it to use. I was thinking something like:

If Me.txtDueDate.oldvalue = Me.txtDueDate.text Then
Else
Call Form_Dirty(0)
End IF


...but where would I put it when the datepicker doesn't trigger any events on the main form??

Sigh....it's Friday and I'm running out of stamina....

Thanks,
T
 
T,

Why not put it in the close event of the datepicker? Or write the old value to a variable in the procedure that opens the datepicker, then refer to it when the datepicker closes.

Yes, the Dirty sub requires the Cancel argument, that's why you kept getting the prompt.

Ken S.
 
Thanks for the help all,

I finally noticed the datepicker triggers the textbox afterupdate event and built something off of there. I think I'm home-free now. There's some 'odd' behavior with displaying a message very briefly at the beginning of the timer before the actual timer starts, when that message should only be seen at the very end when you're out of time, but that's pretty minor. I'll take a look at it Monday for a few minutes and then move on....

Again, thanks.
T
 
Not knowing exactly what you are trying to accomplish with code, let me ask if you've considered comparing the old value to the current value of the control (ctl.OldValue vs. ctl.Value) perhaps on event form_beforeupdate? I used these to determine if a change had occurred or if a first time value entered for a record. Depending on result, I could open a different form and request further information , etc. Doing so, gave me more insight that Dirty event (change only to a record); I wanted to know if the change was a revision from previous data or a Null-to-data).
Jeff
 
Hiya jjl,

Thanks for the reply.

let me ask if you've considered comparing the old value to the current value of the control

That's what Eupher suggested and I initially used it for the datepicker problem. But since the timepicker was different and the .oldvalue wouldn't work for it, I ended up changing the datepicker just for consistency's sake.

Thanks again,
T
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top