By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,534 Members | 2,223 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,534 IT Pros & Developers. It's quick & easy.

populate combo with field-caption-names of a table

P: n/a
Dear all,

How can i populate a combo with the field-caption-names of 1 table?

Thanks

Filip
Nov 13 '05 #1
Share this Question
Share on Google+
5 Replies


P: n/a
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
Nov 13 '05 #2

P: n/a
Field-caption not fieldnames.

Filip

"Bas Cost Budde" <b.*********@heuvelqop.nl> wrote in message
news:cq**********@news2.solcon.nl...
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

Nov 13 '05 #3

P: n/a
Filips Benoit wrote:
Field-caption not fieldnames.


Oh! Sometimes I read sloppy.

Can you live with a function that reads the captions (from the table
definition I presume) and returns a semicolon separated string?

Function getFieldCaptions(cTable As String) As String
Dim cRes As String
Dim db As DAO.Database
Dim td As DAO.TableDef
Dim fd As DAO.Field
On Error Resume Next
Set db = CurrentDb
Set td = db.TableDefs(cTable)
For Each fd In td.Fields
cRes = cRes & fd.Properties("Caption") & ";"
If Err = 3270 Then
Err = 0
cRes = cRes & fd.Name & ";"
End If
Next
Set td = Nothing
getFieldCaptions = Left(cRes, Len(cRes) - 1)
Set db = Nothing
End Function

--
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
Nov 13 '05 #4

P: n/a
thanks˛

"Chuck Grimsby" <c.*******@worldnet.att.net.invalid> wrote in message
news:u7********************************@4ax.com...
On Sat, 18 Dec 2004 15:08:58 GMT, "Filips Benoit"
<be***********@pandora.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?

Nov 13 '05 #5

P: n/a
Chuck Grimsby wrote:
Hope you didn't mind my post to the thread, Bas.
Not at all, not at all!
It was, for me anyways, interesting to see how similar our code was!
And for me. I like your Mid(st,2) because that at least looks less
cluttered than left(st,len(st)-1)--and I figure it executes smoother.
Other languages have constructs to leave out the last n characters, alas
VB hasn't.
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?


I probably confused this with something else. They must be literals of
course.

--
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
Nov 13 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.