UtterAccess.com
X   Site Message
(Message will auto close in 2 seconds)

Welcome to UtterAccess! Please ( Login   or   Register )

Custom Search
 
   Reply to this topicStart new topic
> Change Object Background Colour From Another Form, Access 2010    
 
   
BuzyG
post Jul 11 2018, 08:31 AM
Post#1



Posts: 386
Joined: 20-September 12
From: Cornwall UK


Does anyone know if you can Change an objects BackColor from another form?

I have two subforms "sfmMezLocations" and "sfmFindNoneSerAssets", on a mainform "frmNoneSerAssets"

When I select a record on "sfmFindNoneSerAssets" the record contains the RackLocation etc. I want the corresponding location to be highlighted on "sfmMezLocations"

I have tried the code below, from sfmFindNoneSerAssets, but it's giving me an error 438, The object does not support this property or method.

Also in the final version I need "btn01A01" to be replaced by the variable "MemRackLocation". So the syntax for that would be handy to know too, if it is indeed possible.

CODE
Private Sub Form_Click()
  MemRackLocation = Me![RackLocation]
  Forms!frmNoneSerAssets.sfmMezzLocations.SetFocus
  Forms!frmNoneSerAssets.sfmFindNoneSerAssets.btn01A01.BackColor = RGB(100, 255, 100)
End Sub

--------------------
Live to Surf
Go to the top of the page
 
nuclear_nick
post Jul 11 2018, 08:59 AM
Post#2



Posts: 1,586
Joined: 5-February 06
From: Ohio, USA


I'm assuming from the original post that 'sfmFindNoneSerAssets' is the subform whose control you wish to change. I think you may be missing the complete reference to a control on a subform…

Try changing this...
CODE
Forms!frmNoneSerAssets.sfmFindNoneSerAssets.btn01A01.BackColor = RGB(100, 255, 100)

… to …
CODE
Forms!frmNoneSerAssets!form!sfmFindNoneSerAssets.btn01A01.BackColor = RGB(100, 255, 100)



… or search for more information on how to reference a subform control from the main form. (And unless you really need it, I'd lose the 'setfocus'... JMO...)

--------------------
"Nuclear" Nick
____________
The top three reasons to hide code; 1) It's not your own. 2) It's your own, but it's so crappy you don't want anyone to see it. 3) The comments in your code would get you in a lot of trouble if ever made public.
Go to the top of the page
 
BuzyG
post Jul 11 2018, 09:12 AM
Post#3



Posts: 386
Joined: 20-September 12
From: Cornwall UK


Set focus removed. It was there for something else I was trying.

Tried the change above, alas I now get error 2465, can't find the field "Form"

--------------------
Live to Surf
Go to the top of the page
 
nuclear_nick
post Jul 11 2018, 12:20 PM
Post#4



Posts: 1,586
Joined: 5-February 06
From: Ohio, USA


Sorry. it was a bit of air code... I sometimes forget myself, as it's not something I do a lot.

I think I got something backwards... try...
CODE
Forms!frmNoneSerAssets!sfmFindNoneSerAssets.form.btn01A01.BackColor = RGB(100, 255, 100)

--------------------
"Nuclear" Nick
____________
The top three reasons to hide code; 1) It's not your own. 2) It's your own, but it's so crappy you don't want anyone to see it. 3) The comments in your code would get you in a lot of trouble if ever made public.
Go to the top of the page
 
BuzyG
post Jul 12 2018, 05:11 AM
Post#5



Posts: 386
Joined: 20-September 12
From: Cornwall UK


Thanks for your suggestions Nick

Still getting nowhere fast with this one, if any one has any more thoughts.

I can reference the main form and change control properties no trouble. I can obviously reference the sub form I am currently in and change control properties, using me.

The problem is when I try to change button control properties on the other subform. If the control is a field then access lets me change the data in the field. But when the control is a button I keep getting the errors. iconfused.gif

So this works

CODE
Forms!frmNoneSerAssets.sfmMezzLocations!BoxNumber = "Hello3"


And this works

CODE
Forms!frmNoneSerAssets.btnFlipView.BackColor = RGB(100, 255, 100)


This gives and Error 438, Object Doesn't Support this property or Method

CODE
Forms!frmNoneSerAssets.sfmMezzLocations.btn01A01.BackColor = RGB(100, 255, 100)


And this give an Error 424. Object Required

CODE
Forms!frmNoneSerAssets.Form.sfmMezzLocations.Form.NavigationButtons.btn01A01.BackC
olor = RGB(100, 255, 100)

This post has been edited by BuzyG: Jul 12 2018, 05:14 AM

--------------------
Live to Surf
Go to the top of the page
 
zaxbat
post Jul 12 2018, 05:24 AM
Post#6



Posts: 1,184
Joined: 26-January 06
From: .....the wiregrass (either you know or you don't)


We are having to read an awful lot between the few lines you give for demonstration. Are the subforms datasheets? If so you cannot simply do a background change of color. In fact, you would not want to....you would rather want to simply sync the other subform to show the related record as highlighted/selected. But, as I said, we are having to assume an awful lot with what you have given us.

How about making a screen print and putting it in here so we can see what you are working with?

--------------------
Kindest regards, and Cheers!
ZAX

A picture is worth a thousand words and a zipped DB is worth a thousand pictures.
Oh, and....please don't disappear into the Twilight Zone.... Holler back with your results!
Go to the top of the page
 
BuzyG
post Jul 12 2018, 06:37 AM
Post#7



Posts: 386
Joined: 20-September 12
From: Cornwall UK


Zacbat, alas I can not upload to the Forum from Work and I currently have no working computer at home.

Though it is one specific task I am trying to accomplish. It is the whole principle that seems to not work with the syntax I am using. I have tried dozens of variations spent hours reading example posts.

The problem is I can't find the code to change the background colour of a button on subform A, where the code is run from onclick of a record, on subform B. When the two subforms share a common parent form.

The previous examples hopefully demonstrate, that I am referencing the correct subform and also have the correct code to change the colour of the button. But when I try to combine the two it does not work. iconfused.gif



--------------------
Live to Surf
Go to the top of the page
 
zaxbat
post Jul 12 2018, 06:51 AM
Post#8



Posts: 1,184
Joined: 26-January 06
From: .....the wiregrass (either you know or you don't)


Ah....good, so finally it is more clear what you are doing. Let me spell out what I think you are saying and make sure we are on the same page.

You have a main form with two subforms on it. You want, when somebody selects a record on subform B to change the background color of a command button on subform A? Is that right?

Before I go any further, just need to make sure that this is exactly accurate. Need an answer to that before I go further.

It is tricky to find the proper Access reference to controls on other forms, but it can be done once you understand the scope, associations, and syntax.

--------------------
Kindest regards, and Cheers!
ZAX

A picture is worth a thousand words and a zipped DB is worth a thousand pictures.
Oh, and....please don't disappear into the Twilight Zone.... Holler back with your results!
Go to the top of the page
 
BuzyG
post Jul 12 2018, 07:22 AM
Post#9



Posts: 386
Joined: 20-September 12
From: Cornwall UK


Yes, you summed that up very well with.

"You have a main form with two subforms on it. You want, when somebody selects a record on subform B to change the background color of a command button on subform A? Is that right?"

Now for the interesting part.

--------------------
Live to Surf
Go to the top of the page
 
zaxbat
post Jul 12 2018, 09:39 AM
Post#10



Posts: 1,184
Joined: 26-January 06
From: .....the wiregrass (either you know or you don't)


I am guessing that subform B is a datasheet (or maybe a continuous form). If so, I would recommend using then 'on current' event....that way it will fire each time the selected record changes and no clicking is needed.

However, if subform B is a single form....actually, I think the on current still fires when you change records.

Anyway, this should change the button color of the other form.....works here....
CODE
Option Compare Database
Option Explicit

Private Sub Form_Current()
Dim mycolor As Long
On Error Resume Next
   If AssetID Mod 2 = 1 Then
      mycolor = 32776
   Else
      mycolor = 0
   End If
   Forms("frmNoneSerAssets").Form.Controls("sfmMezLocations").Form.Controls("btn01A01").BackColor = mycolor
End Sub

This post has been edited by zaxbat: Jul 12 2018, 10:28 AM

--------------------
Kindest regards, and Cheers!
ZAX

A picture is worth a thousand words and a zipped DB is worth a thousand pictures.
Oh, and....please don't disappear into the Twilight Zone.... Holler back with your results!
Go to the top of the page
 
BuzyG
post Jul 13 2018, 04:02 AM
Post#11



Posts: 386
Joined: 20-September 12
From: Cornwall UK


Many thanks zaxbat. notworthy.gif

Sometimes the simplest looking things take longer than you think. I have substituted my "MemRackLocation" Variable in to your code. Now subform "A" highlights the physical location of the part selected from the datasheet view on subform "B", when a user selects that line. Tis a shame I can't post up a screen shot, it's quite fun. The weekend will be sweeter now.

CODE
Forms("frmNoneSerAssets").Form.Controls("sfmMezzLocations").Form.Controls(MemRackLocation).BackColor = RGB(100, 255, 100)

This post has been edited by BuzyG: Jul 13 2018, 04:04 AM

--------------------
Live to Surf
Go to the top of the page
 
zaxbat
post Jul 13 2018, 06:48 AM
Post#12



Posts: 1,184
Joined: 26-January 06
From: .....the wiregrass (either you know or you don't)


Glad that worked for you....wish you continued success in your project.

--------------------
Kindest regards, and Cheers!
ZAX

A picture is worth a thousand words and a zipped DB is worth a thousand pictures.
Oh, and....please don't disappear into the Twilight Zone.... Holler back with your results!
Go to the top of the page
 


Custom Search
RSSSearch   Top   Lo-Fi    23rd September 2018 - 02:00 AM