Drop Down list values with Table/Query Heading

ootkhopdi

Registered User.
Local time
Today, 22:32
Joined
Oct 17, 2013
Messages
181
Hi


I want to create a drop down table field in access form, in this list
values should be Column headings of a table/ query.


like this


if table A column titles are
Name Post School


then list items should be Name,Post,School.
if i add one more column in table i.e. class then it should add in drop list values.


how can i do this.. please tell me solution
 
Hi. Just add a combobox on your form and either use the Wizard or select "Field List" as the Row Source Type.


Just to be clear, the combobox properties might look something like this:


Row Source: NameOfYourTableHere
Row Source Type: Field List


Hope it helps...
 
Last edited:
Create your combo and add the table fields required to the combo row source....or use * to select all fields. Make sure the number of columns equals the fields to be displayed.

If you add a field, using * means it will automatically be included. Otherwise add it manually. In each case increase the number of columns by 1
 
Nope. He wants field names to be elements of the drop down, not field values. If his table has 5 fields and 200 rows in it, he wants 5 items in the drop down--the field names.

Field names don't exist in any tables in Access, but you can obtain them in a recordset. I don't know how to load a drop down from a recordset, but I can give some code to get the field names.
 
Hi plog....
If he does want a field list then just use field list as the row source type as the DBguy has already said. No code needed
 
What dbGuy will work for a query but for a table it will show the field name and not the the field caption for a table. That may be OK. If you need the field caption here is code that will allow you to select a table name and get the captions as well if you need that.

Code:
Public Sub LoadFieldList(tableName As String)
  Dim tdf As TableDef
  Dim db As DAO.Database
  Dim fld As DAO.Field
  Dim VisibleName As String
  Dim strFields As String
  Set db = CurrentDb
  Set tdf = db.TableDefs(tableName)
  On Error GoTo errlbl
  For Each fld In tdf.Fields
    VisibleName = fld.Name
    'now check for a description property if it fails then take the field nam
    VisibleName = fld.Properties("Caption")
    If strFields = "" Then
      strFields = VisibleName
    Else
      strFields = strFields & ";" & VisibleName
    End If
  Next fld
  Me.lstFields.RowSourceType = "value list"
  Me.lstFields.RowSource = strFields
  Exit Sub
errlbl:
  Resume Next
End Sub
 
Wow, I apologize.

I had been playing with getting field names from the system earlier today and it has been a pain. I assumed achieving what ook wanted would be too.

DBguy nailed it. Wish I could use his solution for my issue.
 
Hi MajP. There's always a catch, isn't there? Thanks!
 
Hi MajP. There's always a catch, isn't there?
Yes, the only reason this occurred to me was because a few days ago another OP asked the exact same question and they were specific about field captions.
 
Thanks to All for helping me.


now i get another issue,


if i select a field in combo box 1, then how can i get all values of field in table


like.




if i select Name field in Combo box 1, then all values of Field "NAME" should be displayed in Combo box 2.


Thanks once again to all
 
add code to the AfterUpdate event of Combo1:
Code:
Private Sub Combo1_AfterUpdate()
   Me.Combo2.RowSource = "select [" & Me.Combo1 & "] From yourTable;"
   Me.Combo2.Requery
End Sub
 
merry xmas to you and your family!
 
Thanks arnelgp
and same to you and your family..








one more question


May i got Text box 12 value =DLookup("[Me.combobox1]", "Datatable", "[Combobox2] =" & Forms![Details]![Combobox2])
 

Users who are viewing this thread

Back
Top Bottom