On Dirty style event for all pages of a tab control

R

Repent

I have a form that uses the tab control.
The tab control has 5 tabs/pages.
on the form's "on dirty" event i have code that changes the form to a
red color and plugs some warning text into a label control on the
bottom of the 1st page of the tab control. the warning states to the
user that they have changed a record and if they proceed the record
will be changed and saved. They can hit Esc to cancel the changes and
the warning box and red color go away.

I would like to have this same feature on all tabs because the user
can change the record anywhere on any tab.

I copied/pasted the label box from the first page of the tab control
to the other pages of the tab control. When I make a change to the
other tabs, other than the first tab, the box does change to red but
the text is not displayed. This tells me at least that the first part
of the code is running but the rest is not.

Here is the code I have so far:

Private Sub Form_Dirty(Cancel As Integer)
If Not Me.NewRecord Then

Me.Detail.BackColor = RGB(255, 100, 100)

Me.InfoMessage.Caption = "You have modified this record. " & _
"If you move to another record, your changes will be applied. " & _
"To cancel your changes, hit the Esc key (top left of keyboard)."
End If

End Sub


How do I modify the code to get the event to fire for any tab page
where the record is being changed?

thanks all;
chris
 
L

Linq Adams via AccessMonster.com

Tabbed pages of a form are not separate entities but rather merely extensions
of the form. The OnDirty event is, indeed, firing, regardless of which page
the changes are being made on. The problem is that when you copy and then
past a control (the label InfoMessage in this case) the copy of the control
you made is given a different name by Access! You obviously cannot have two
controls on a given form with the same name! You need to include your message
in the captions of these new labels as well as the original label. For
simplicity's sake, I would do something like:

LabelWarning = "You have modified this record. " & _
"If you move to another record, your changes will be applied. " & _
"To cancel your changes, hit the Esc key (top left of keyboard)." .

Then

Me.InfoMessage.Caption = LabelWarning
Me.2ndPageLabel = LabelWarning
Me.3rdPageLabel = LabelWarning
Me.4thPageLabel = LabelWarning

and so forth.
 
L

Linq Adams via AccessMonster.com

As an alternative, you could actually move your tabbed control out of the way,
copy then paste the label in question to an appropriate position on the form,
then move the tabbed control back into place. Since the label is on the
underlying form rather than on a single page of the tabbed control, it will
show thru on all pages and you can leave your code as is..
 
R

Repent

Linq;

I tried your second idea first as it's the simplest and it works so
I'm going with that. Thank you so very much!!

chris
 

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