Results 1 to 4 of 4
  1. #1
    Join Date
    Jun 2004
    Posts
    92

    Unanswered: Help with For.. Each.. Next..

    So I can't find this anywhere and the search function here isn't what it used to be but I need some help with using for.. each.. next.. with tables.

    What I want is something like:

    For each record in tblemail
    if [active] = true then
    emaillist = emaillist & [emailaddress] & ";"
    end if
    next

    I want to automate creating an email list for a function off of the entries in a table where the [active] field is true. The table only contains fields [emailaddress] and [active].

    I know how to do for.. each.. next.. in forms but can't figure out and can't find information for searching tables.

    Any help would be greatly appreciated.

    Thanks,

    Josh

  2. #2
    Join Date
    Jan 2007
    Location
    UK
    Posts
    11,434
    Provided Answers: 10
    For Each emailaddress In tblemail
    if [active] = true then
    emaillist = emaillist & [emailaddress] & ";"
    end if
    next emailaddress


    Try that.
    George
    Home | Blog

  3. #3
    Join Date
    Dec 2002
    Location
    Préverenges, Switzerland
    Posts
    3,740
    is there a reason to avoid using a recordset?

    const cstFwdOnly as integer = 8 'might not have dao referenced
    dim emaillist as string
    with currentdb.openrecordset("SELECT emailaddress FROM tblemail WHERE active=true", cstFwdOnly)
    do while not .eof
    emaillist = emaillist & !emailaddress & "; "
    .movenext
    loop
    end with

    izy
    currently using SS 2008R2

  4. #4
    Join Date
    Jun 2004
    Posts
    92
    Thanks izy, that works great. The only reason why I wasn't looking at using a recordset was because I don't have much experience using them. I guess I've never had the need. Although since it made this a lot easier I'll have to read up about them. It looks simple enough; create a sort of adhoc table using simple sql.

Posting Permissions

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