Populating Combo Boxes - why doesn't this work all the time?

amorts

Board Regular
Joined
Jan 4, 2006
Messages
181
I am using the following code to populate some of my combo boxes;

Private Sub form_Open(Cancel As Integer)
With combFilter
.RowSourceType = "Table/Query"
.RowSource = "<Name of Query>"
End With
End Sub

I find that this is quite tempermental. If works for some on some but not on others. I have ran the query and checked it produces the desired results. However, when I drop down the box in run time it is blank.

Any ideas?
 

Some videos you may like

Excel Facts

How can you automate Excel?
Press Alt+F11 from Windows Excel to open the Visual Basic for Applications (VBA) editor.

VicRauch

Well-known Member
Joined
Mar 23, 2006
Messages
2,032
You show .RowSource = "". That is not a query. and therefore nothing would ever show up in your combo box.
 

amorts

Board Regular
Joined
Jan 4, 2006
Messages
181
Sorry I forgot the tags on here would have taken that out.

I actually typed .RowSource= "qryName" but I put optional brackets around it originally!
 

VicRauch

Well-known Member
Joined
Mar 23, 2006
Messages
2,032
Could you post the SQL for the query? If it works by itself, but not for the combo box, the SQL would be a help to understand what is going on.

Something else to look at is the properties of the combo box. How many columns do you have defined, and which of these columns do you have set to a width of zero, for non-display of that column?
 

Norie

Well-known Member
Joined
Apr 28, 2004
Messages
75,809
Office Version
  1. 365
Platform
  1. Windows
Is qryName the actual name of the query?

Or is it a variable holding the name of the query?
 

amorts

Board Regular
Joined
Jan 4, 2006
Messages
181
It's really strange I have just deleted and recreated the combo box and done the same with the query and it has now decided to work.

I had this same problem yesterday too!

Thanks for your help though guys.
 

Watch MrExcel Video

Forum statistics

Threads
1,108,611
Messages
5,523,889
Members
409,542
Latest member
Shezz01

This Week's Hot Topics

Top