![]() | |
![]() |
| | Thread Tools | Display Modes |
#1
| |||
| |||
|
#2
| |||
| |||
|
|
Dear all, How can i populate a combo with the field-caption-names of 1 table? |
#3
| |||
| |||
|
|
Filips Benoit wrote: Dear all, How can i populate a combo with the field-caption-names of 1 table? Set the RowSourceType of the combo to "Field List" -- Bas Cost Budde, Holland http://www.heuveltop.nl/BasCB/msac_index.html I prefer human mail above automated so in my address replace the queue with a tea |
#4
| |||
| |||
|
|
Field-caption not fieldnames. |
#5
| |||
| |||
|
|
On Sat, 18 Dec 2004 15:08:58 GMT, "Filips Benoit" benoit.filips (AT) pandora (DOT) be> wrote: How can i populate a combo with the field-caption-names of 1 table? In the form's code module, put the code below, adjusting the name of the table and the combo box's name to be whatever the heck you need it to be: Private Sub Form_Load() Dim strTemp As String strTemp = FieldCaptionsOfATable("MyTable") Me.myCombo.RowSource = strTemp End Sub Private Function FieldCaptionsOfATable( _ strTableName As String) _ As String Dim myDB As DAO.Database Dim TDF As DAO.TableDef Dim FLD As DAO.Field Dim strCaptions As String Set myDB = CurrentDb Set TDF = myDB.TableDefs(strTableName) On Error Resume Next For Each FLD In TDF.Fields strCaptions = strCaptions & ";" & _ Chr$(34) & FLD.Properties("Caption") & Chr$(34) Select Case Err.Number Case 0 ' do nothing, no error occured. Case 3270 ' No caption, so use the field name: strCaptions = strCaptions & ";" & _ Chr$(34) & FLD.Properties("Name") & Chr$(34) End Select Err.Clear Next On Error GoTo 0 FieldCaptionsOfATable = Mid$(strCaptions, 2) End Function -- Shell To Dos... Come In Dos... Do You Copy? |
#6
| |||
| |||
|
|
Hope you didn't mind my post to the thread, Bas. |
|
It was, for me anyways, interesting to see how similar our code was! |
|
For what it's worth, you're also going to need to put double quotes (Chr$(34) around the captions to get them to show up in the list. Unless you know something I don't? |
![]() |
| Thread Tools | |
| Display Modes | |
| |