Results 1 to 5 of 5

Thread: dynamic field names

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Dec 2001
    Posts
    23

    Question dynamic field names

    I have a program that will connect to different databases depending on the information sent to it.

    Instead of hardcoding the recordset fields into the program I'd like to know if i can define the fields at runtime.

    Instead of:
    "rsProject!project_id"
    I'd like:
    "rsProject!<AnyString>"

    I hope this is enough information.

    Thanks

  2. #2
    Fanatic Member Gaffer's Avatar
    Join Date
    Nov 2000
    Location
    London
    Posts
    828
    You can use this format - rs("myField")

    e.g.

    strFld = "myField"
    debug.print rs(strFld)

  3. #3
    Frenzied Member swatty's Avatar
    Join Date
    Aug 2002
    Location
    somewhere on earth
    Posts
    1,478
    Or you can use
    VB Code:
    1. s = "project_id"
    2. rsProject.Fields(s)
    Code:
    If Question = Incomplete Then
       AnswerNextOne
    Else
       ReplyIfKnown
    End If
    cu Swatty

  4. #4

    Thread Starter
    Junior Member
    Join Date
    Dec 2001
    Posts
    23
    Thanks for the help.

  5. #5
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974
    You can also use numbers to get the field, eg:

    VB Code:
    1. Dim I as Integer
    2. For I = 0 to rsProject.Fields.Count -1  '(fields is 0 based)
    3.   Msgbox rsProject.Fields(I)
    4. Next I

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