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?
 

Excel Facts

Remove leading & trailing spaces
Save as CSV to remove all leading and trailing spaces. It is faster than using TRIM().

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
76,353
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.
 

Forum statistics

Threads
1,175,915
Messages
5,900,265
Members
434,825
Latest member
Shooter_99999

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Top