Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Listing field names in a form

Status
Not open for further replies.

RobJDB

Programmer
May 13, 2002
44
GB
How would I populate a text box on an Access 2k form with a list of field names from a table?
 
Here is something that might help. This block of code was used to dynamically set up a form with however number of fields were in a selected lookup table. It did this by loading the field names into an array and then when the form opens it would create the form based on entries in the array. Anyhow, the code you need to do what you want is in there. You will have to just pull it out.

Code:
        For Each varItem In CurrentDb.TableDefs
            If varItem.name = Me.txtObjModule Then
                TheRecordSource = Me.txtObjModule
                If varItem.Fields.Count > 5 Then
                    MsgBox ("To many fields in lookup table")
                Else
                    For i = 0 To varItem.Fields.Count - 1
                        strField(i) = varItem.Fields(i).name
                    Next i
                    For i = (varItem.Fields.Count) To 4
                        strField(i) = ""
                    Next i
                End If
            End If
        Next varItem
        
        str_Frm = "frmLookupMaint"
        If FormIsLoaded(str_Frm) Then DOCMD.Close acForm, str_Frm

        DOCMD.OpenForm str_Frm
        DOCMD.Maximize
 
Thanks for that, it looks useful.

Rob
 
Hi!

Another thing you can do is create a list box and set the row source type to Field List and the row source to your table name. A list of the fields from that table will be in the list box.

hth
Jeff Bridgham
bridgham@purdue.edu
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top