Results 1 to 5 of 5

Thread: SQL question on referencing field with index

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Sep 1999
    Posts
    154
    I have a table with the following fields: Name, text1, text2, text3.

    In the following code example (Which does not work) i am trying to figure out a way to reference a recordset field using an integer. I can not reference rc!texti. Is there a way to use the value of i so that rc!text + the i will be allowed in code?????? The reason I need to do this is in the live data I have Text1 thru Text34.

    *****************************
    Dim db as database
    Dim rc as recordset
    Dim strSQL as string
    Dim i as integer

    for i = 1 to 3

    strSQL = "Select * from Table where Text" & i & " not null;"
    Set DB...
    Set RC...

    rc!texti = "Hi There"

    next i

  2. #2
    old fart Frans C's Avatar
    Join Date
    Oct 1999
    Location
    the Netherlands
    Posts
    2,926
    rc("text" & CStr(i)) = "Hi There"

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Sep 1999
    Posts
    154
    Thanks so much. Works Great.

  4. #4
    PowerPoster BruceG's Avatar
    Join Date
    May 2000
    Location
    New Jersey (USA)
    Posts
    2,657
    In principle, your SQL statement should work as is. The problem I see is in the statement:
    rc!Texti = "Hi there"
    The problem is that you can't use an expression when you reference a field with the "bang" (!) operator. Try this instead:
    rc.Fields("Text" & i)
    "It's cold gin time again ..."

    Check out my website here.

  5. #5
    PowerPoster BruceG's Avatar
    Join Date
    May 2000
    Location
    New Jersey (USA)
    Posts
    2,657
    Hey! Frans beat me to it. He took advantage of the fact that ".Fields" is optional.
    "It's cold gin time again ..."

    Check out my website here.

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