ComboBox column names

  • Thread starter Thread starter john
  • Start date Start date
J

john

I need to retrieve the name of the columns of the combobox, which is based
on a dynamic query coded into its rowsource, but do not see a property for
that. Is there a way to get them thru code?

If not, is there a way to reference the rowsource query in the same way as a
saved query, in that, the rowsource does not have a given name.

John
 
You could open a recordset using the same SQL statement ...

Private Sub Command2_Click()

Dim rst As ADODB.Recordset

Me.Combo0.RowSource = "SELECT CategoryID AS CatNum, CategoryName AS
CatName FROM Categories"
Set rst = New ADODB.Recordset
With rst
.ActiveConnection = CurrentProject.Connection
.Open Me.Combo0.RowSource
MsgBox "The name of the first column is: " & rst.Fields(0).Name &
vbCrLf & _
"The name of the second column is: " & rst.Fields(1).Name
.Close
End With

End Sub

--
Brendan Reynolds (MVP)
http://brenreyn.blogspot.com

The spammers and script-kiddies have succeeded in making it impossible for
me to use a real e-mail address in public newsgroups. E-mail replies to
this post will be deleted without being read. Any e-mail claiming to be
from brenreyn at indigo dot ie that is not digitally signed by me with a
GlobalSign digital certificate is a forgery and should be deleted without
being read. Follow-up questions should in general be posted to the
newsgroup, but if you have a good reason to send me e-mail, you'll find
a useable e-mail address at the URL above.
 
john said:
I need to retrieve the name of the columns of the combobox, which is based
on a dynamic query coded into its rowsource, but do not see a property for
that. Is there a way to get them thru code?

If not, is there a way to reference the rowsource query in the same way as a
saved query, in that, the rowsource does not have a given name.


In AXP, you can do this:

strName = Me.combobox.Recordset.Fields(0).Name
 
Back
Top