Results 1 to 7 of 7
  1. #1
    Join Date
    Feb 2004
    Posts
    42

    Unanswered: Table Values to String

    Is there an easy way to take a column of data from a table and turn it into a string that I can use in a text box?

    For example, I have a Table tblInfo, with a field fldStatus (all text) that contains the data:

    [fldStatus]
    CLOSE
    COMP
    INPRG
    HOLD

    and I want to put it in a text box in this format:

    CLOSE, COMP, INPRG, HOLD


    Thanks for your help!

  2. #2
    Join Date
    Jan 2004
    Location
    Toronto, Canada
    Posts
    259
    Dim conn as adodb.connection
    Dim rec as adodb.recordset

    set conn = currentproject.connectoin
    set rec = new adodb.recordset

    rec.Open "SELECT [FieldName] FROM [TableName]", conn, adOpenStatic, adLockOptimistic

    Dim tempstring as string

    for i = 1 to rec.RecordCount
    tempstring = tempstring + " " + rec(i).Value
    next

  3. #3
    Join Date
    Feb 2004
    Posts
    42
    Thanks for the help, but now I am getting this error when I run the code:

    Run-time error 3265:

    Item cannot be found in the collection corresponding to the requested name or ordinal.


    It then highlights this line:
    tempstring = tempstring + ", " + rec(i).Value


    Any thoughts???
    Thanks

  4. #4
    Join Date
    Jan 2004
    Location
    Toronto, Canada
    Posts
    259
    thats becus it went to a value of i which was not in the record collection; in a sense, you tried to access the 1000th value when there were only 999;

    to fix it, change the for i = 1 to rec.recordcount to

    for i = 0 to rec.recordcount - 1

    if that doesn't work...try

    for i = 1 to rec.recordcount - 1

  5. #5
    Join Date
    Feb 2004
    Posts
    42
    Originally posted by Jerrie
    thats becus it went to a value of i which was not in the record collection; in a sense, you tried to access the 1000th value when there were only 999;

    to fix it, change the for i = 1 to rec.recordcount to

    for i = 0 to rec.recordcount - 1

    if that doesn't work...try

    for i = 1 to rec.recordcount - 1
    That was my first thought also, but that did not solve it...anything else?

  6. #6
    Join Date
    Jan 2004
    Location
    Toronto, Canada
    Posts
    259
    drats! sry, i used it the wrong way....shoulda seen that..; hehe, can make mistakes..

    replace that entire for "i = 1.. ...next" with this:

    Do Until rec.EOF
    tempstring = tempstring + " " + rec(0).Value
    rec.MoveNext
    Loop

    sry!

  7. #7
    Join Date
    Feb 2004
    Posts
    42
    Got it, thanks for the help!!!

Posting Permissions

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