Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium


ColumnHeader of ComboBox?

Posted on 2003-02-20
Medium Priority
Last Modified: 2008-03-06
How do I get in code the ColumnHeader of a specific Column of a ComboBox?
(The combox Box is on a form..Not created in code)
Question by:tbsgadi
1 Comment
LVL 41

Accepted Solution

shanesuebsahakarn earned 400 total points
ID: 7986448
You could use something like this:

Dim rst As DAO.Recordset
Dim fld As Field

Set rst = CurrentDb.OpenRecordset(Me!Combo1.RowSource)
For Each fld In rst.Fields
   MsgBox fld.Name
Set rst = Nothing

This retrieves the field names of the query on which the combo is based, but does not take into account hidden columns in the combo.

You could put it into a function (warning, this is air code!):

Function GetColHead(ComboName as String, ColNum As Long) As String
Dim rst As DAO.Recordset

Set rst = CurrentDb.OpenRecordset(Me(ComboName).RowSource)
GetColHead = rst(ColNum).Name
Set rst = Nothing
End Function

Put the function into the form, and call it with something like:

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Instead of error trapping or hard-coding for non-updateable fields when using QODBC, let VBA automatically disable them when forms open. This way, users can view but not change the data. Part 1 explained how to use schema tables to do this. Part 2 h…
Explore the ways to Unlock VBA Project Password Excel 2010 & 2013 documents. Go through the article and perform the steps carefully to remove VBA Excel .xls file.
In Microsoft Access, learn how to use Dlookup and other domain aggregate functions and one method of specifying a string value within a string. Specify the first argument, which is the expression to be returned: Specify the second argument, which …
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.

580 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question