473,503 Members | 11,968 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Use variable to set label backcolor

tuxalot
200 New Member
I am trying to set the backcolor of a label and am getting a type mismatch. This code fires in the after update event of the combobox.

strColor = vbRed in this example. I have also tried it using hex values. In the underlying table for cboSourceType, Column 3 is a text data type.

Expand|Select|Wrap|Line Numbers
  1.     Me!lblColor.BackColor = FFFFFF
  2.     strColor = cboSourceType.Column(3)
  3.     MsgBox strColor
  4.     Me!lblColor.BackColor = strColor
Oct 18 '11 #1
5 7120
Stewart Ross
2,545 Recognized Expert Moderator Specialist
In line 1 you need to tell VBA interpreter that the value concerned is hex using the &H operator:

Expand|Select|Wrap|Line Numbers
  1. Me!lblColor.BackColor = &HFFFFFF
-Stewart
Oct 18 '11 #2
Rabbit
12,516 Recognized Expert Moderator MVP
vbRed is just a constant for the number 255. Convert your colors to its corresponding base 10 number.
Oct 18 '11 #3
Stewart Ross
2,545 Recognized Expert Moderator Specialist
Another comment about your original code segment is that the Backcolor property is numeric. Although Access often converts types on the fly you mention that the column in your combo you are using is text. I'd suggest you use the Val function to convert the value explicitly to a numeric value.

-Stewart
Oct 18 '11 #4
tuxalot
200 New Member
Thanks for the advice.
Oct 18 '11 #5
NeoPa
32,557 Recognized Expert Moderator MVP
Also, VBA has a whole bunch of colour constants defined for use - including vbBlack, vbWhite, vbRed, vbBlue, ... The list goes on. Code is far neater if such mnemonics are used in place of literal numbers with no obvious connection to their use.
Oct 18 '11 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

4
17199
by: Dave | last post by:
Hi, Can anyone tell me the correct syntax when using a variable to control the color property? This works ok: If ABC2flash Then Label61.BackColor = Color.Yellow This doesn't, showing...
2
1221
by: CharlieOz1 | last post by:
Hi, I am having trouble with the datagrid. I have a label in an ItemTemplate. I have a simple function in the label which I have tested and works (the function does pass back a...
8
1686
by: Ankit Aneja | last post by:
I'm trying to use a for() loop to go through a set of labels and set their visibility to false. I had to do something like Code: for(int i=1;i<=10;i++) { labeli.visible = false;
6
2130
by: QT | last post by:
Dear sirs, I want to create panel or label field for each database records. I am using following codes for each database row to create panel field. 'Panel ' i = 1
1
3848
by: John_H | last post by:
Re: ASP.NET 2.0 I would like suggestions or code examples on how to collect a variable length list of input data (item# & item quantity specifically). I thought that I could accomplish this...
3
6494
by: melanieab | last post by:
Hi, I'd like to put a transparent label over a textbox. I set the label backcolor to transparent, and set its parent as the textbox. But setting the textbox as the parent resulted in the label...
0
2380
by: weiwei | last post by:
Hi; I am having trouble to get variable from grid view. here is my scenario. I want to delete a row in database from web page, in additon, I also want to delete that user's directory in c:drive. ...
6
2892
by: Dmitry Duginov | last post by:
Hi, I have the following label markup (label is inside FormView): <asp:Label ID="lblIndicatorReady" runat="server" Text="RE" ToolTip="Ready" BackColor='<%#...
1
1655
Mladen
by: Mladen | last post by:
Hi, i'm new in VB and I like to know how can I change the Label BackColor but it generate error when i try whit codes.Plase help me Mladen
0
7098
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7296
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7364
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
7017
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7470
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5604
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
5026
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4696
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
405
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.