CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5
  1. #1
    Join Date
    Dec 2002
    Posts
    55

    How do I populate a combobox with Field names

    from an Access DB Table? I can do it with Records from the field but I can't figure out how to get the Field names.

    Set dbEquipSetF1 = OpenDatabase("C:\Program Files\PageMe\Pageme.mdb")
    Set rstEquipSetF1 = dbEquipSetF1.OpenRecordset("EquipmentSetF1", dbOpenDynaset)

    With rstEquipSetF1
    Do While Not .EOF
    cboEquipSet.AddItem .Fields
    .MoveNext
    Loop
    End With

    I'm not even close...
    Thanks
    Relentless
    Last edited by Relentless; April 19th, 2005 at 03:28 PM.

  2. #2
    Join Date
    Sep 2001
    Location
    Québec, Canada
    Posts
    1,923

    Re: How do I populate a combobox with Field names

    Well you could use DAO in vb too, but if you want to use ADO, you can use ADOX:

    http://www.codeguru.com/forum/showth...hreadid=203405

    JeffB
    CodeGuru VB FAQ Visual Basic Frequently Asked Questions
    VB Code color Tool to color your VB code on CodeGuru
    Before you post Importants informations to know before posting

  3. #3
    Join Date
    Dec 2002
    Posts
    55

    Re: How do I populate a combobox with Field names

    Thanks for the suggestion, Jeff, but I'm using VB5 and I don't think it supports ADO.

    Rel

  4. #4
    Join Date
    Sep 2001
    Location
    Québec, Canada
    Posts
    1,923

    Re: How do I populate a combobox with Field names

    Ok, sry I kinda looked your code a bit quick. You don't need a recordset at all, the FIELDS description is hold into the TABLEDEFS structure which is into the DATABASE object, for example, you can browse them like that:

    Code:
        Dim db As DAO.Database
        Dim x As Integer
         
        Set db = DAO.OpenDatabase("E:\bdtest.mdb")
         
        For x = 0 To db.TableDefs("tbltext").Fields.Count - 1
         
            Debug.Print db.TableDefs("tbltext").Fields(x).Name
         
        Next x
         
         
        db.Close
         
        Set db = Nothing
    JeffB
    CodeGuru VB FAQ Visual Basic Frequently Asked Questions
    VB Code color Tool to color your VB code on CodeGuru
    Before you post Importants informations to know before posting

  5. #5
    Join Date
    Dec 2002
    Posts
    55

    Re: How do I populate a combobox with Field names

    Many thanks Jeff...I bow to your brilliance.

    Rel

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured