[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Populate combo box with column names of table

Posted on 2005-05-03
5
Medium Priority
?
371 Views
Last Modified: 2008-02-01
I need to populate a combo box (combo31) with the column names of the table chosen in another combo box (combo1).  I can go into the properties of Combo31 and choose a row source type of "Field List" and then enter a table name for the Row Source but that leaves the column names only being populated by the table entered.  I need something that displays the column names based on the value chosen in combo1.  I tried things like entering "me.combo1.value" in the Row Source box but no luck.

Any ideas???  Thanks!
0
Comment
Question by:ajslentz
  • 2
  • 2
5 Comments
 
LVL 120

Accepted Solution

by:
Rey Obrero (Capricorn1) earned 2000 total points
ID: 13922708
try this

cboRefTable is the combo where you select the table Name
cboFieldName is the combo that will list the names of the fields of the table selected


set the row source of cboRefTable to

SELECT MSysObjects.Name, MSysObjects.Type
FROM MSysObjects
WHERE ((MSysObjects.Name) Not Like "msys*") AND ((MSysObjects.Type)=1)



Private Sub cboRefTable_AfterUpdate()
Dim tdf As TableDef, strField As String, db As DAO.Database
Dim intFld As Integer, strFieldList As String
Set db = CurrentDb
Set tdf = db.TableDefs("" & Me.cboRefTable & "")
With tdf
    For intFld = 0 To .Fields.Count - 1
        strField = .Fields(intFld).Name
        strFieldList = strFieldList & ";" & [strField]
    Next
End With

If Len(strFieldList) > 0 Then
    strFieldList = Mid(strFieldList, 2)
End If
    Me.cboFieldName.RowSourceType = "Value List"
    Me.cboFieldName.RowSource = strFieldList
End Sub
0
 
LVL 17

Expert Comment

by:Arji
ID: 13922717
Depending on what column in Combo1 has the value(assume it's in column(0)

[Combo31].Rowsource = "Select field1, field2 from YourTable where field1 = " & [Combo31].Column(0)

Field1, field2 are generic field names you would need to replace with your field names.  Field1 is used here as the field in which you want to sort [Combo31] by.  [Combo31].Column(0) is the value in Column(0) of the combobox.
0
 
LVL 17

Expert Comment

by:Arji
ID: 13922724
Also, you should set the Row Source Type of [Combo31] to Table/Query and set up your column widths and count.
0
 

Author Comment

by:ajslentz
ID: 13922787
capricorn1, that was AWESOME!!!  Thanks so much.  Here is what I used...  Thanks again!!!

Private Sub Combo1_AfterUpdate()
Me.Combo31 = ""
Dim tdf As TableDef, strField As String, db As DAO.Database
Dim intFld As Integer, strFieldList As String
Set db = CurrentDb
Set tdf = db.TableDefs("" & Me.Combo1 & "")
With tdf
    For intFld = 0 To .Fields.Count - 1
        strField = .Fields(intFld).Name
        strFieldList = strFieldList & ";" & [strField]
    Next
End With

If Len(strFieldList) > 0 Then
    strFieldList = Mid(strFieldList, 2)
End If
    Me.Combo31.RowSourceType = "Value List"
    Me.Combo31.RowSource = strFieldList
End Sub
0
 
LVL 120

Expert Comment

by:Rey Obrero (Capricorn1)
ID: 13922891
U R welcome!!!
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

Windows Explorer lets you open cabinet (cab) files like any other folder. In VBA you can easily handle normal files and folders, but opening and indeed creating cabinet files takes a lot more - and that's you'll find here.
In a use case, a user needs to close an opened report by simply pressing the Escape (Esc) key. This can be done by adding macro code in Report_KeyPress or Report_KeyDown event.
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
Look below the covers at a subform control , and the form that is inside it. Explore properties and see how easy it is to aggregate, get statistics, and synchronize results for your data. A Microsoft Access subform is used to show relevant calcul…
Suggested Courses

873 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