A Microsoft Office (Excel, Word) forum. OfficeFrustration

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » OfficeFrustration forum » Microsoft Access » Using Forms
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

Changing BackColor Property of Main Form Label from SubForm



 
 
Thread Tools Display Modes
  #1  
Old April 2nd, 2008, 07:54 PM posted to microsoft.public.access.forms
access user
external usenet poster
 
Posts: 78
Default Changing BackColor Property of Main Form Label from SubForm

Hi,

My main form is called "MRA Form_JPS" and has a child sub-form called
"subfrm_Aneurism". When the value of a control on the subform called
"Aneurism" reaches more than 4, I want the backcolor of a label called
"Label113" on the main form to go vbred, so I coded the following thinking I
had it

Private Sub Aneurism_AfterUpdate()

If Me.Aneurism 4 Then
Me.[MRA Form_JPS]!Label113.BackColor = vbRed
Else
Me.[MRA Form_JPS]!Label113.BackColor = vbWhite
End If

End Sub

but it doesn't work yet.

Is there something goofy about the way the above's wrote, or does it have to
do with the fact that Aneurism gets its values automatically from this VBA
code below:

Private Sub Form_BeforeUpdate(Cancel As Integer)

Me.[Aneurism] = Nz(DMax("[Aneurism]", "qry_Aneurism_JPS", "ID=" _
& Me.ID), 0) + 1

End Sub

???
  #2  
Old April 2nd, 2008, 08:26 PM posted to microsoft.public.access.forms
M Skabialka
external usenet poster
 
Posts: 570
Default Changing BackColor Property of Main Form Label from SubForm

Try changing 'Me' to 'Forms' as you are on a subform and that subform is Me
and the main form is an entirely separate object.
Forms![MRA Form_JPS]!Label113.BackColor

"Access User" wrote in message
...
Hi,

My main form is called "MRA Form_JPS" and has a child sub-form called
"subfrm_Aneurism". When the value of a control on the subform called
"Aneurism" reaches more than 4, I want the backcolor of a label called
"Label113" on the main form to go vbred, so I coded the following thinking
I
had it

Private Sub Aneurism_AfterUpdate()

If Me.Aneurism 4 Then
Me.[MRA Form_JPS]!Label113.BackColor = vbRed
Else
Me.[MRA Form_JPS]!Label113.BackColor = vbWhite
End If

End Sub

but it doesn't work yet.

Is there something goofy about the way the above's wrote, or does it have
to
do with the fact that Aneurism gets its values automatically from this VBA
code below:

Private Sub Form_BeforeUpdate(Cancel As Integer)

Me.[Aneurism] = Nz(DMax("[Aneurism]", "qry_Aneurism_JPS", "ID=" _
& Me.ID), 0) + 1

End Sub

???



  #3  
Old April 2nd, 2008, 09:02 PM posted to microsoft.public.access.forms
access user
external usenet poster
 
Posts: 78
Default Changing BackColor Property of Main Form Label from SubForm

Well, I guess we tried but still no cigar...I changed my VBA to conform

Private Sub Aneurism_AfterUpdate()

If Me.Aneurism 4 Then
Forms![MRA Form_JPS]!Label113.BackColor = vbRed
Else
Forms![MRA Form_JPS]!Label113.BackColor = vbWhite
End If

End Sub

but nothing seemingly has been affected.

???
"M Skabialka" wrote:

Try changing 'Me' to 'Forms' as you are on a subform and that subform is Me
and the main form is an entirely separate object.
Forms![MRA Form_JPS]!Label113.BackColor

"Access User" wrote in message
...
Hi,

My main form is called "MRA Form_JPS" and has a child sub-form called
"subfrm_Aneurism". When the value of a control on the subform called
"Aneurism" reaches more than 4, I want the backcolor of a label called
"Label113" on the main form to go vbred, so I coded the following thinking
I
had it

Private Sub Aneurism_AfterUpdate()

If Me.Aneurism 4 Then
Me.[MRA Form_JPS]!Label113.BackColor = vbRed
Else
Me.[MRA Form_JPS]!Label113.BackColor = vbWhite
End If

End Sub

but it doesn't work yet.

Is there something goofy about the way the above's wrote, or does it have
to
do with the fact that Aneurism gets its values automatically from this VBA
code below:

Private Sub Form_BeforeUpdate(Cancel As Integer)

Me.[Aneurism] = Nz(DMax("[Aneurism]", "qry_Aneurism_JPS", "ID=" _
& Me.ID), 0) + 1

End Sub

???




  #4  
Old April 2nd, 2008, 09:12 PM posted to microsoft.public.access.forms
Maurice
external usenet poster
 
Posts: 1,585
Default Changing BackColor Property of Main Form Label from SubForm

try this:

Me.Parent!Label113.BackColor = vbRed

the main form can be refered to as parent...

hth
--
Maurice Ausum


"Access User" wrote:

Well, I guess we tried but still no cigar...I changed my VBA to conform

Private Sub Aneurism_AfterUpdate()

If Me.Aneurism 4 Then
Forms![MRA Form_JPS]!Label113.BackColor = vbRed
Else
Forms![MRA Form_JPS]!Label113.BackColor = vbWhite
End If

End Sub

but nothing seemingly has been affected.

???
"M Skabialka" wrote:

Try changing 'Me' to 'Forms' as you are on a subform and that subform is Me
and the main form is an entirely separate object.
Forms![MRA Form_JPS]!Label113.BackColor

"Access User" wrote in message
...
Hi,

My main form is called "MRA Form_JPS" and has a child sub-form called
"subfrm_Aneurism". When the value of a control on the subform called
"Aneurism" reaches more than 4, I want the backcolor of a label called
"Label113" on the main form to go vbred, so I coded the following thinking
I
had it

Private Sub Aneurism_AfterUpdate()

If Me.Aneurism 4 Then
Me.[MRA Form_JPS]!Label113.BackColor = vbRed
Else
Me.[MRA Form_JPS]!Label113.BackColor = vbWhite
End If

End Sub

but it doesn't work yet.

Is there something goofy about the way the above's wrote, or does it have
to
do with the fact that Aneurism gets its values automatically from this VBA
code below:

Private Sub Form_BeforeUpdate(Cancel As Integer)

Me.[Aneurism] = Nz(DMax("[Aneurism]", "qry_Aneurism_JPS", "ID=" _
& Me.ID), 0) + 1

End Sub

???




  #5  
Old April 2nd, 2008, 09:19 PM posted to microsoft.public.access.forms
access user
external usenet poster
 
Posts: 78
Default Changing BackColor Property of Main Form Label from SubForm

I tried this w/o oberving any changes:


Private Sub Aneurism_AfterUpdate()

If Me.Aneurism 4 Then
Me.Parent!Label113.BackColor = vbRed
Else
Me.Parent!Label113.BackColor = vbWhite
End If

End Sub

"Maurice" wrote:

try this:

Me.Parent!Label113.BackColor = vbRed

the main form can be refered to as parent...

hth
--
Maurice Ausum


"Access User" wrote:

Well, I guess we tried but still no cigar...I changed my VBA to conform

Private Sub Aneurism_AfterUpdate()

If Me.Aneurism 4 Then
Forms![MRA Form_JPS]!Label113.BackColor = vbRed
Else
Forms![MRA Form_JPS]!Label113.BackColor = vbWhite
End If

End Sub

but nothing seemingly has been affected.

???
"M Skabialka" wrote:

Try changing 'Me' to 'Forms' as you are on a subform and that subform is Me
and the main form is an entirely separate object.
Forms![MRA Form_JPS]!Label113.BackColor

"Access User" wrote in message
...
Hi,

My main form is called "MRA Form_JPS" and has a child sub-form called
"subfrm_Aneurism". When the value of a control on the subform called
"Aneurism" reaches more than 4, I want the backcolor of a label called
"Label113" on the main form to go vbred, so I coded the following thinking
I
had it

Private Sub Aneurism_AfterUpdate()

If Me.Aneurism 4 Then
Me.[MRA Form_JPS]!Label113.BackColor = vbRed
Else
Me.[MRA Form_JPS]!Label113.BackColor = vbWhite
End If

End Sub

but it doesn't work yet.

Is there something goofy about the way the above's wrote, or does it have
to
do with the fact that Aneurism gets its values automatically from this VBA
code below:

Private Sub Form_BeforeUpdate(Cancel As Integer)

Me.[Aneurism] = Nz(DMax("[Aneurism]", "qry_Aneurism_JPS", "ID=" _
& Me.ID), 0) + 1

End Sub

???



  #6  
Old April 3rd, 2008, 02:32 AM posted to microsoft.public.access.forms
Allen Browne
external usenet poster
 
Posts: 11,706
Default Changing BackColor Property of Main Form Label from SubForm

If you expect this to change color in the main form as you move record in
the subform, you would need to use the subform's Current event, as well as
the AfterUpdate event of the *form* (not control.) Example below.

Private Sub Form_Current()
Dim lngColor As Long

If Me.Aneurism 4 Then
lngColor = vbRed
Else
lngColor = vbWhite
End If

With Me.Parent!Label113
If .BackColor lngColor Then
.BackColor = lngColor
End If
End With
End Sub

Private Sub Form_AfterUpdate()
Call Form_Current()
End Sub

--
Allen Browne - Microsoft MVP. Perth, Western Australia
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.

"Access User" wrote in message
...

My main form is called "MRA Form_JPS" and has a child sub-form called
"subfrm_Aneurism". When the value of a control on the subform called
"Aneurism" reaches more than 4, I want the backcolor of a label called
"Label113" on the main form to go vbred, so I coded the following thinking
I
had it

Private Sub Aneurism_AfterUpdate()

If Me.Aneurism 4 Then
Me.[MRA Form_JPS]!Label113.BackColor = vbRed
Else
Me.[MRA Form_JPS]!Label113.BackColor = vbWhite
End If

End Sub

but it doesn't work yet.

Is there something goofy about the way the above's wrote, or does it have
to
do with the fact that Aneurism gets its values automatically from this VBA
code below:

Private Sub Form_BeforeUpdate(Cancel As Integer)

Me.[Aneurism] = Nz(DMax("[Aneurism]", "qry_Aneurism_JPS", "ID=" _
& Me.ID), 0) + 1

End Sub

???


  #7  
Old April 3rd, 2008, 02:30 PM posted to microsoft.public.access.forms
access user
external usenet poster
 
Posts: 78
Default Changing BackColor Property of Main Form Label from SubForm

Yes, thanks lots, this works on the main form, but I wanted to show you the
current state of the VBA in that sub-form because it doesn't work quite as I
would've thought it could. You may be able to suss out the cunundrum by
perusing it (see below)

Option Compare Database
Option Explicit

Private Sub Aneurism_AfterUpdate()

Call Form_Current

End Sub

Private Sub Form_BeforeUpdate(Cancel As Integer)

Me.[Aneurism] = Nz(DMax("[Aneurism]", "qry_Aneurism_JPS", "ID=" _
& Me.ID), 0) + 1

End Sub

Private Sub Form_Current()

Dim lngColor As Long

If Me.Aneurism 4 Then
lngColor = vbRed
Else
lngColor = vbWhite
End If

With Me.Parent!Label113
If .BackColor lngColor Then
.BackColor = lngColor
End If
End With

End Sub

Private Sub Form_AfterUpdate()

Call Form_Current

End Sub


I think you'll probably agree that there's a need for a modification or two
or three.

Thanks in any event - it's an improvement.



"Allen Browne" wrote:

If you expect this to change color in the main form as you move record in
the subform, you would need to use the subform's Current event, as well as
the AfterUpdate event of the *form* (not control.) Example below.

Private Sub Form_Current()
Dim lngColor As Long

If Me.Aneurism 4 Then
lngColor = vbRed
Else
lngColor = vbWhite
End If

With Me.Parent!Label113
If .BackColor lngColor Then
.BackColor = lngColor
End If
End With
End Sub

Private Sub Form_AfterUpdate()
Call Form_Current()
End Sub

--
Allen Browne - Microsoft MVP. Perth, Western Australia
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.

"Access User" wrote in message
...

My main form is called "MRA Form_JPS" and has a child sub-form called
"subfrm_Aneurism". When the value of a control on the subform called
"Aneurism" reaches more than 4, I want the backcolor of a label called
"Label113" on the main form to go vbred, so I coded the following thinking
I
had it

Private Sub Aneurism_AfterUpdate()

If Me.Aneurism 4 Then
Me.[MRA Form_JPS]!Label113.BackColor = vbRed
Else
Me.[MRA Form_JPS]!Label113.BackColor = vbWhite
End If

End Sub

but it doesn't work yet.

Is there something goofy about the way the above's wrote, or does it have
to
do with the fact that Aneurism gets its values automatically from this VBA
code below:

Private Sub Form_BeforeUpdate(Cancel As Integer)

Me.[Aneurism] = Nz(DMax("[Aneurism]", "qry_Aneurism_JPS", "ID=" _
& Me.ID), 0) + 1

End Sub

???



  #8  
Old April 3rd, 2008, 02:40 PM posted to microsoft.public.access.forms
access user
external usenet poster
 
Posts: 78
Default Changing BackColor Property of Main Form Label from SubForm

I guess I should be less vague about how I think it will work: when the
threshold value of 4 is exceeded, I think the main form label should go red
and remain red until the offending record gets removed.

The other aspect of the behavior in this sub-form that I'm finding is
unexpected is as follows: if the user returns to the sub-form at a later
point and modifies an entry on one of the records, then the value of Aneurism
of that record is incremented, which I don't want happening. Is there a
workaround to that?

Thx!

"Allen Browne" wrote:

If you expect this to change color in the main form as you move record in
the subform, you would need to use the subform's Current event, as well as
the AfterUpdate event of the *form* (not control.) Example below.

Private Sub Form_Current()
Dim lngColor As Long

If Me.Aneurism 4 Then
lngColor = vbRed
Else
lngColor = vbWhite
End If

With Me.Parent!Label113
If .BackColor lngColor Then
.BackColor = lngColor
End If
End With
End Sub

Private Sub Form_AfterUpdate()
Call Form_Current()
End Sub

--
Allen Browne - Microsoft MVP. Perth, Western Australia
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.

"Access User" wrote in message
...

My main form is called "MRA Form_JPS" and has a child sub-form called
"subfrm_Aneurism". When the value of a control on the subform called
"Aneurism" reaches more than 4, I want the backcolor of a label called
"Label113" on the main form to go vbred, so I coded the following thinking
I
had it

Private Sub Aneurism_AfterUpdate()

If Me.Aneurism 4 Then
Me.[MRA Form_JPS]!Label113.BackColor = vbRed
Else
Me.[MRA Form_JPS]!Label113.BackColor = vbWhite
End If

End Sub

but it doesn't work yet.

Is there something goofy about the way the above's wrote, or does it have
to
do with the fact that Aneurism gets its values automatically from this VBA
code below:

Private Sub Form_BeforeUpdate(Cancel As Integer)

Me.[Aneurism] = Nz(DMax("[Aneurism]", "qry_Aneurism_JPS", "ID=" _
& Me.ID), 0) + 1

End Sub

???



  #9  
Old April 3rd, 2008, 02:56 PM posted to microsoft.public.access.forms
Allen Browne
external usenet poster
 
Posts: 11,706
Default Changing BackColor Property of Main Form Label from SubForm

I guess I'm not clear about how you have this form connected up.

Typically one record in a main form has many records in the subform. It
would be much easier just to use Conditional Formatting on the bad record in
the subform itself, rather than to try to mess with code that changes colors
in the main form. You could do it without any code at all.

I didn't follow as to the Aneurism record self-incrementing. That's not
normal in Access, so there may be come code that's assigning a value to the
field, perhaps in Form_Current or some other event.

--
Allen Browne - Microsoft MVP. Perth, Western Australia
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.

"Access User" wrote in message
...
I guess I should be less vague about how I think it will work: when the
threshold value of 4 is exceeded, I think the main form label should go
red
and remain red until the offending record gets removed.

The other aspect of the behavior in this sub-form that I'm finding is
unexpected is as follows: if the user returns to the sub-form at a later
point and modifies an entry on one of the records, then the value of
Aneurism
of that record is incremented, which I don't want happening. Is there a
workaround to that?

Thx!

"Allen Browne" wrote:

If you expect this to change color in the main form as you move record in
the subform, you would need to use the subform's Current event, as well
as
the AfterUpdate event of the *form* (not control.) Example below.

Private Sub Form_Current()
Dim lngColor As Long

If Me.Aneurism 4 Then
lngColor = vbRed
Else
lngColor = vbWhite
End If

With Me.Parent!Label113
If .BackColor lngColor Then
.BackColor = lngColor
End If
End With
End Sub

Private Sub Form_AfterUpdate()
Call Form_Current()
End Sub

--
Allen Browne - Microsoft MVP. Perth, Western Australia
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.

"Access User" wrote in message
...

My main form is called "MRA Form_JPS" and has a child sub-form called
"subfrm_Aneurism". When the value of a control on the subform called
"Aneurism" reaches more than 4, I want the backcolor of a label called
"Label113" on the main form to go vbred, so I coded the following
thinking
I
had it

Private Sub Aneurism_AfterUpdate()

If Me.Aneurism 4 Then
Me.[MRA Form_JPS]!Label113.BackColor = vbRed
Else
Me.[MRA Form_JPS]!Label113.BackColor = vbWhite
End If

End Sub

but it doesn't work yet.

Is there something goofy about the way the above's wrote, or does it
have
to
do with the fact that Aneurism gets its values automatically from this
VBA
code below:

Private Sub Form_BeforeUpdate(Cancel As Integer)

Me.[Aneurism] = Nz(DMax("[Aneurism]", "qry_Aneurism_JPS", "ID=" _
& Me.ID), 0) + 1

End Sub

???




  #10  
Old April 3rd, 2008, 03:32 PM posted to microsoft.public.access.forms
access user
external usenet poster
 
Posts: 78
Default Changing BackColor Property of Main Form Label from SubForm

You are quite ritght....there is a one to many child/parent form/sub-form
relationship established on these two. I have used the enabled=no, locked=yes
properties on the Aneurism subform control AND also done a CF on it when it
reached 4 BUT (and here's the rub), it turns out there's some kind of 'bug'
in Access that releases the enabled/locked features when a CF is reached, so
even though the Aneurism ctrl turns beet red when it's 4, user can enter it
with his cursor. Soooo... I thought I would remove the CF in order to protect
the Aneurism ctrl via the enable/protect properties and place a label on the
main form with suitable verbiage advising against advancing beyond the
threshold amount and turning it red when'er it's transcended and until it's
deleted.

I will look into your hypothesized cause and get back.

"Allen Browne" wrote:

I guess I'm not clear about how you have this form connected up.

Typically one record in a main form has many records in the subform. It
would be much easier just to use Conditional Formatting on the bad record in
the subform itself, rather than to try to mess with code that changes colors
in the main form. You could do it without any code at all.

I didn't follow as to the Aneurism record self-incrementing. That's not
normal in Access, so there may be come code that's assigning a value to the
field, perhaps in Form_Current or some other event.

--
Allen Browne - Microsoft MVP. Perth, Western Australia
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.

"Access User" wrote in message
...
I guess I should be less vague about how I think it will work: when the
threshold value of 4 is exceeded, I think the main form label should go
red
and remain red until the offending record gets removed.

The other aspect of the behavior in this sub-form that I'm finding is
unexpected is as follows: if the user returns to the sub-form at a later
point and modifies an entry on one of the records, then the value of
Aneurism
of that record is incremented, which I don't want happening. Is there a
workaround to that?

Thx!

"Allen Browne" wrote:

If you expect this to change color in the main form as you move record in
the subform, you would need to use the subform's Current event, as well
as
the AfterUpdate event of the *form* (not control.) Example below.

Private Sub Form_Current()
Dim lngColor As Long

If Me.Aneurism 4 Then
lngColor = vbRed
Else
lngColor = vbWhite
End If

With Me.Parent!Label113
If .BackColor lngColor Then
.BackColor = lngColor
End If
End With
End Sub

Private Sub Form_AfterUpdate()
Call Form_Current()
End Sub

--
Allen Browne - Microsoft MVP. Perth, Western Australia
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.

"Access User" wrote in message
...

My main form is called "MRA Form_JPS" and has a child sub-form called
"subfrm_Aneurism". When the value of a control on the subform called
"Aneurism" reaches more than 4, I want the backcolor of a label called
"Label113" on the main form to go vbred, so I coded the following
thinking
I
had it

Private Sub Aneurism_AfterUpdate()

If Me.Aneurism 4 Then
Me.[MRA Form_JPS]!Label113.BackColor = vbRed
Else
Me.[MRA Form_JPS]!Label113.BackColor = vbWhite
End If

End Sub

but it doesn't work yet.

Is there something goofy about the way the above's wrote, or does it
have
to
do with the fact that Aneurism gets its values automatically from this
VBA
code below:

Private Sub Form_BeforeUpdate(Cancel As Integer)

Me.[Aneurism] = Nz(DMax("[Aneurism]", "qry_Aneurism_JPS", "ID=" _
& Me.ID), 0) + 1

End Sub

???




 




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump


All times are GMT +1. The time now is 02:23 PM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 OfficeFrustration.
The comments are property of their posters.