Results 1 to 2 of 2
  1. #1
    Gold Lounger
    Join Date
    Jan 2004
    Location
    Italy
    Posts
    3,245
    Thanks
    0
    Thanked 0 Times in 0 Posts

    same with access instead excel (2000 sr-1)

    I use this little code to fill each LABEL in useform with range of excel sheet.
    Is possible to use the same(Arranged naturally...) to fill each LABEL in form of VB based the title of Fields of access table?
    Tks.
    ............
    Dim M, X
    Sheets(FOGLIO).Select

    For M = 1 To 16
    Me.Controls.Item("LABEL" & M) = Sheets(FOGLIO).Cells(2, M).Value
    Next
    .........

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: same with access instead excel (2000 sr-1)

    You can open a recordset (DAO or ADODB) on the table, and loop through the fields of the recordset - let's say that the recordset is named rst:

    Dim M As Integer
    For M = 1 To rst.Fields.Count
    Me.Controls("LABEL" & M) = rst.Fields(M - 1).Name
    Next M

    (We use Fields(M-1) because the fields start numbering at 0, not at 1.)

Posting Permissions

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