473,385 Members | 1,753 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Creating an If/Then/Else Statement for a combo box that allows multiple values in VBA

1
Good Morning,

I am new to this forum, and extremely new to VBA, so there may be a very simple explanation to this. I also apologize if I am giving you and excessive amount of detail. I have a table, tblAdmissions. One of the columns is for Certification and was set up as a lookup field that allows multiple values to be selected. In my form, the label for this field is called lblCertification, and the combo box is called cboCertification. I am trying to write an If/Then/Else statement that will turn the fore color in the label and the fore color combo box red if a certain value is selected. I wrote the following code:
Expand|Select|Wrap|Line Numbers
  1.     If Me.cboCertification = "Other" Then
  2.     Me.lblCertification.ForeColor = vbCyan
  3.     Else
  4.     Me.lblCertification.ForeColor = vbRed
  5.     End If
When I try to use this code I get the following message, "Run time error '13': Type mismatch." This basic formula has worked everywhere else in the form, but I suspect since this combo box allows multiple values there is something I am not taking into account.
I am sorry if this is a ridiculously easy question. Thank you for any help you are able to provide.
Sep 14 '09 #1

✓ answered by mshmyob

Data Type mismatch has to do with the data type you are checking for.

I am assuming that your combo box has 2 columns at least, with the key column hidden. Therefore when you say check for "Other" you are comparing the key column (which is probably a number) to a text value ("Other")

Use the column property (Me.cboCertification.column(0) or Me.cboCertification.column(1)) to compare the proper values.

Column(0) would refer to the hidden key column and column(1) would refer to your textual column that you actually are seeing in the combo box.

cheers,

2 8400
mshmyob
904 Expert 512MB
Data Type mismatch has to do with the data type you are checking for.

I am assuming that your combo box has 2 columns at least, with the key column hidden. Therefore when you say check for "Other" you are comparing the key column (which is probably a number) to a text value ("Other")

Use the column property (Me.cboCertification.column(0) or Me.cboCertification.column(1)) to compare the proper values.

Column(0) would refer to the hidden key column and column(1) would refer to your textual column that you actually are seeing in the combo box.

cheers,
Sep 14 '09 #2
NeoPa
32,556 Expert Mod 16PB
I suspect Mshmyob is absolutely right about your issue. An alternative solution would be to compare your ComboBox value with the numeric equivalent of "Other" of course. The type of the value of the ComboBox will be the same as the field in the BoundColumn property. If the BoundColumn is 1, then the first field in the record source determines the Value of the control. If it's 2 then the second does, etc.
Sep 14 '09 #3

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

Similar topics

3
by: Indraneel Sheorey | last post by:
Hello, I want to set up a query in SQL Server that is "grouped by" a variable PRICE. Since PRICE takes on continuous decimal values, I want to create deciles based on this variable and then...
21
by: Sharon | last post by:
I wish to build a framework for our developers that will include a singleton pattern. But it can not be a base class because it has a private constructor and therefore can be inherit. I thought...
3
by: rreitsma | last post by:
I want to create a form that will allow the user to select from a list of available reports and based on a filter limit the records displayed in the report. I have figured out how to access the...
7
by: Harris | last post by:
Dear all, I have the following codes: ====== public enum Enum_Value { Value0 = 0, Value1 = 10,
5
by: keri | last post by:
Hi, I have a table with 2 fields - flddate and category. The values of flddate are all working day dates (monday to friday dates between jan 2007 and 2010 (although the end date could change)....
5
by: KewlToyZ | last post by:
Good day, I am stuck in a strange situation. SQL 2000 Server, creating a stored procedure to use in Crystal Reports 11. I am trying to build a report without creating a table or temprorary table in...
13
by: jkimbler | last post by:
As part of our QA of hardware and firmware for the company I work for, we need to automate some testing of devices and firmware. Since not everybody here knows C#, I'm looking to create a new...
3
Kelicula
by: Kelicula | last post by:
This is NOT a complete OO perl tutorial However I thought it could be beneficial to explain some of the basic concepts, and allow some users to simplify the software design process. I have...
5
by: irkahs | last post by:
Hey all, Alright. So I have this "Combobox" in an ASP page (a box which allows multiple selection using the CTRL key) and I am trying to pass the values selected from it into another ASP page...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
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
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...

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.