473,396 Members | 1,864 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

populate combo with field-caption-names of a table

Dear all,

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

Thanks

Filip
Nov 13 '05 #1
5 2437
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
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
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Support4John | last post by:
a2k (9.0.6926) SP-3 Jet 4.0 SP-7 I have a form with combo box field that allows the user to select from the combo box or type in the field value that may or maynot be in the combo box field. ...
4
by: godber | last post by:
I need to populate text boxes for instance with employee information using their unique employee works number selected from a combo box. Can anyone help, I am told thru visual basic this can be...
4
by: Mike L | last post by:
I'm open for any suggestions on how to better program this. I want the user to select a license from a combo box, cboPrivilege and then the user will click the add button, then a record will be...
11
by: DSR | last post by:
Help Please... I would like to populate a combo box on a form with a query that compares data from two tables. Any record that is unique in table1 should continue to populate my combobox. The...
16
by: agrawal.solutions | last post by:
Hello Friends I am asking a very silly question but i dont find any solution fo this.. I am selectiong a recordset and want to populate a combobox where id would be inviseble and the content...
3
by: David | last post by:
I am trying to use Dlookup to populate a text box on a form, but haven't had any good luck so far. I've looked here at the posts and have used the Access help for examples. Northwind is way over...
1
by: indhu | last post by:
Hi all, I want 2 know, how to populate using 2 combo box to populate other field. right now am using click event of combo to populate the other field but i want to select both combo1 and combo2 ...
2
by: Robertjb1 | last post by:
First Post - New member - I've searched the discussions available to no avail. I have, however, learned a few things in doing so. (Great Site -- Thanks) My issue is as follows: Access 2003/WinXP...
3
by: PGM | last post by:
I am trying to populate a combo box using a simple SQL query to a database but all I get in the combo box is "System._ComObject" . Any suggestions are greatly appreciated On Error Resume Next ...
1
by: cluless | last post by:
Hey everybody, I have a database with one major form that has a few subforms and a listbox, and on the form there are buttons that link to other forms as well. Once the list box is clicked on, the...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.