color code?

johnseito

Registered User.
Local time
Today, 13:19
Joined
Feb 27, 2013
Messages
89
Code:
 If Discontinued Then
      Me!ProductName.BackColor = 255
 End If

discountinued is an option button and productname is a textbox.

I use a code like this, and 255 is red. But when I checked to see for other color options, I see 255 is also yellow as per this website.

http://www.endprod.com/colors/

And what does Hex, R, G, B, and MSAccess mean?
Thanks!!
 

Attachments

  • color.jpg
    color.jpg
    43.8 KB · Views: 126
I see 255 is also yellow as per the website but the 255 is on the Hex column and I don't really know what Hex, R, G, or B is?

but I guess MSAccess means those color code is for Access and I tried a couple and it works. :-)
 
Last edited:
R G B is the red green blue mix to give the colour, it is a notation that can be used and frequently appears in help

Red is 255 0 0
Green 0 255 0
Yellow 255 255 0

The hex notation which I think came in from 2007 reflects this as red is #FF0000 and yellow # FFFF00
FF IS 255 in hexadecimal a number system with a base of 16

Brian
 
Last edited:
Some colors have names. vbRed, vbYellow, vbGreen, etc. Your If won't work the way it is written if the form has the ability to scroll to other records. You need to code the color for the Else path also.
Code:
If Discontinued Then
    Me.txtProductName.BackColor = vbRed
Else
    Me.txtProductName.BackColor = vbBlack
End If

Keep in mind that you are referring to a property of a control, NOT the field itself and so you should use the control's Name property which for best practice should be different from the name of the bount field.
 
Ok, I noticed the code only work when I select the option box and then select the form into design view then click it into form view. I then see the color working.

but when I have it as form view, and then I just click select and deselect the option box, the color for the text box doesn't appear.

Why is that?
 
and I also wonder what is the difference between

me!productname.backcolor =vbblack

vs

me.productname.backcolor = vbblack.
 
with this code that you provided:
and most of my codes are like this which is not efficient, is that
it only works properly when I open the form in design view then open it
again in form view, sort of like resetting it.

It would be more effective if it is not like that, and it changes color when a user select or un select the discontinued option button.

Private Sub Form_Current()
If Discontinued Then
Me.ProductName.BackColor = vbRed
Else
Me.ProductName.BackColor = vbBlack
End If
End sub
 
Have you looked at Conditional Formatting? I think this will resolve your issue, especially if this is a continuous Form.
 
The Current event fires when you navigate to a new record. If you want to colorize the current record on a change of status, you must execute that code. You could call the current event or if the current event does other stuff also, you could move the colorize code to a sub and call it from both places.

As Gina mentioned, you can use conditional formatting for this also. In some cases, conditional formatting is your only option.

The difference between bang and dot is when the reference gets evaluated. The dot gets evaluated at compile time and the bang gets evaluated at execution time. So, you will get compile errors if you use the dot correctly. This is desirable since you don't want your user being the person to discover the reference error. You will also get intellisense which will save you typing and show you what methods and properties are available for a control.

When referring to controls, in some cases you can use either method but in others, you will need to use the dot. In general, the bang is used to reference something you define (which in the case of controls is ONLY the ControlSource's Value property) whereas the dot is used to reference something Access defines. The thing that crosses the line is fields that are bound to the form/report RecordSource. Access adds those items to its list of objects which allows you to use the dot to reference them. When you give controls names different from the name of their ControlSource, you can reference them independently.
 
Have you looked at Conditional Formatting? I think this will resolve your issue, especially if this is a continuous Form.

Ok, thanks. How do you do a conditional formatting? And how do you know this is a continuous form, and what does a continuous form mean?


Actually I think the reason why it only runs the code when I open in design view, then form view is because the code is in this

Private Sub Form_Current()

End Sub

I was just trying to understand what Sub Form_Current() does, so I looked it up on google and that code happen to be on this website. Thanks :-)

http://office.microsoft.com/en-us/access-help/HV080751555.aspx
 
The dot gets evaluated at compile time and the bang gets evaluated at execution time.

Compile time runs first and then the execution time right?


When referring to controls, in some cases you can use either method but in others, you will need to use the dot. In general, the bang is used to reference something you define (which in the case of controls is ONLY the ControlSource's Value property) whereas the dot is used to reference something Access defines. The thing that crosses the line is fields that are bound to the form/report RecordSource. Access adds those items to its list of objects which allows you to use the dot to reference them. When you give controls names different from the name of their ControlSource, you can reference them independently.

Ok I will have to try those two and then I will find out. Thanks
 
Also with the code I often get a Run-time error '94':

Invalid use of Null

if I close the form and then open it again. I suspect is because the Discontinued
option button is blank.


Code:
If Discontinued Then
    Me.ProductName.BackColor = vbRed
Else
    Me.ProductName.BackColor = vbBlack
End If
 
!. How do you do a conditional formatting?

Please state which version of Acess so I can post the correct directions.

2. And how do you know this is a continuous form, and what does a continuous form mean?

I don't know that is I said *if this is a continuous Form*. Are you you saying you don't know what a continuous form is?


3. Actually I think the reason why it only runs the code when I open in design view, then form view is because the code is in this

Private Sub Form_Current()

End Sub

No, the code will run when you change records.

4. I was just trying to understand what Sub Form_Current() does...

The On_Current event of a Form runs every time you change records. Sounds to me like you are learning access. So, perhaps these will help...

Jeff Conrad's resources page...
http://www.accessmvp.com/JConrad/accessjunkie/resources.html

The Access Web resources page...
http://www.mvps.org/access/resources/index.html

A free tutorial written by Crystal (MS Access MVP)...
http://allenbrowne.com/casu-22.html

MVP Allen Browne's tutorials...
http://allenbrowne.com/links.html#Tutorials

Sample data models...
http://www.databasedev.co.uk/table-of-contents.html
http://www.databaseanswers.org/data_models/

Naming Conventions…
http://www.access-diva.com/d1.html

Other helpful tips…
Setting up a Model Database
http://www.access-diva.com/d11.html

My Database Standards...
http://regina-whipp.com/blog/?p=102
 
Interesting, a lot of good things. So much to know with so little time.

I have installed on my computer access 2007 and 2010, but I would say I often use 2010.

No, I don't know what a continuous form is. :-(
 
I'm not going to try and jump in since you've got such wonderful people helping you; except to say that you definitely don't wont multiple versions of access installed on your machine at once.
 
@speakers...

While, for the most part, I agree I have several machines with several versions of Access installed. Biggest problem is the lag when you switch versions.
 
I'm not going to try and jump in since you've got such wonderful people helping you; except to say that you definitely don't wont multiple versions of access installed on your machine at once.

I noticed often time, when I have two version of access sometimes I just open an application and it's a bit tedious in telling which one version the application is open to or when a database is saved I often don't know exactly which one is save to.

I installed two just in case if I find a program or a sample that is more gear toward one or the other so it would be easy for me to just open in that version etc.

I got lots of things to learn with very little time. :-(
 

Users who are viewing this thread

Back
Top Bottom