dbTalk Databases Forums  

populate combo with field-caption-names of a table

comp.databases.ms-access comp.databases.ms-access


Discuss populate combo with field-caption-names of a table in the comp.databases.ms-access forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Filips Benoit
 
Posts: n/a

Default populate combo with field-caption-names of a table - 12-18-2004 , 09:08 AM






Dear all,

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

Thanks

Filip



Reply With Quote
  #2  
Old   
Bas Cost Budde
 
Posts: n/a

Default Re: populate combo with field-caption-names of a table - 12-18-2004 , 10:05 AM






Filips Benoit wrote:
Quote:
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


Reply With Quote
  #3  
Old   
Filips Benoit
 
Posts: n/a

Default Re: populate combo with field-caption-names of a table - 12-18-2004 , 11:16 AM



Field-caption not fieldnames.

Filip

"Bas Cost Budde" <b.costbudde (AT) heuvelqop (DOT) nl> wrote

Quote:
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



Reply With Quote
  #4  
Old   
Bas Cost Budde
 
Posts: n/a

Default Re: populate combo with field-caption-names of a table - 12-18-2004 , 06:18 PM



Filips Benoit wrote:
Quote:
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


Reply With Quote
  #5  
Old   
Filips Benoit
 
Posts: n/a

Default Re: populate combo with field-caption-names of a table - 12-19-2004 , 04:44 AM



thanksē

"Chuck Grimsby" <c.grimsby (AT) worldnet (DOT) att.net.invalid> wrote

Quote:
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?




Reply With Quote
  #6  
Old   
Bas Cost Budde
 
Posts: n/a

Default Re: populate combo with field-caption-names of a table - 12-19-2004 , 09:28 AM



Chuck Grimsby wrote:
Quote:
Hope you didn't mind my post to the thread, Bas.
Not at all, not at all!

Quote:
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.

Quote:
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


Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.