Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

I need help with referencing a combo box in VBA 1

Status
Not open for further replies.

JoshC

IS-IT--Management
Mar 12, 2001
8
US
I am having problems with storing a value from a combo box in a VBA variable. The code I have been using has worked wonderfully, however, I am having a problem when I reference a column in the combo box beyond 2.
ex: strcboEmployeeType = Me!cboEmployee.Column(3)
I always get an error message that says "Invalid use of Null" and highlights that line. I have checked that the row source for my combo box references the correct field in my query (SELECT [QryLogOn].[Name], [QryLogOn].[Password], [QryLogOn].[EmployeeID], [QryLogOn].[EmployeeType] FROM QryLogOn; ), and that my query references the correct field in my table, and that the Employee Type field is not null in either the table or the query. I can type
Print Me!cboEmployee.Column(3) into the "Immediate" window when I am debugging, and it returns "Null." Can a combo box not hold more than 3 columns? Is there a way around this?
Also, (if I get this working) should I change strcboEmployeeType to a boolean since it references a Yes/No field, or is it ok to leave it as a string?
I would appreciate any help!
Josh C.
 
Hi Josh,
For all intents and purpose, this should work perfectly. Check that your combobox column count is, well, at least 4. Remember: columns in a combobox are 0 based column 1 that you see is really called column(0). Gord
ghubbell@total.net
 
Does changing my Row Source Property to

"SELECT [QryLogOn].[Name], [QryLogOn].[Password], [QryLogOn].[EmployeeID], [QryLogOn].[EmployeeType] FROM QryLogOn;"

from

"SELECT [QryLogOn].[Name], [QryLogOn].[Password], [QryLogOn].[EmployeeID] FROM QryLogOn;"

not add the fourth column?
Josh C.
 
Nevermind. I feel really dumb. :O) I had the Column Count property set to 2. I changed it to 4, and all is fixed.
thanks!
Josh
 
Josh: Way to go! and if I had a dollar for everytime I made that same slip.....!!! Gord
ghubbell@total.net
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top