Results 1 to 3 of 3
  1. #1
    Join Date
    May 2005
    Posts
    1,191

    Unanswered: For each record in a table...

    Is it possible to go through each record in a table (which happens to be a user table in my case), and check if one of the fields equals something?

    For example, say in this table, I store the user's name, department and email (among other things). Is it possible to go through each record, check if they belong to the right department, and add their email to a string?

    Here's what I've tried so far, but it doesn't like my boolean in the If statement...
    Code:
    Dim strEmailTo As String
    strEmailTo = ""
    Dim dbs As DAO.Database
    Set dbs = currentdb
    Dim rstTable As DAO.Recordset
    Set rstTable = dbs.OpenRecordset("Tbl_Users", dbOpenDynaset)
    Do While Not rstTable.EOF
            If ![Fld_User_Dpt] = "DepartmentA" Then
                strEmailTo = strEmailTo & Nz(![Fld_User_Email], "") & "; "
            End If
            rstTable.MoveNext
    Loop
    Me.Geek = True

  2. #2
    Join Date
    May 2005
    Posts
    1,191
    After I posted, I saw I forgot to tell it to use the table. It's Friday

    Here it is for anyone interested:
    Code:
    Dim strEmailTo As String
    strEmailTo = ""
    Dim dbs As DAO.Database
    Set dbs = currentdb
    Dim rstTable As DAO.Recordset
    Set rstTable = dbs.OpenRecordset("Tbl_Users", dbOpenDynaset)
    Do While Not rstTable.EOF
            If rstTable![Fld_User_Dpt] = "DepartmentA" Then
                strEmailTo = strEmailTo & Nz(rstTable![Fld_User_Email], "") & "; "
            End If
            rstTable.MoveNext
    Loop
    Me.Geek = True

  3. #3
    Join Date
    May 2005
    Location
    Nevada, USA
    Posts
    2,888
    Provided Answers: 6
    May not matter in what I assume is a fairly small table, but it would be more efficient to open the recordset on an SQL string that restricted to the desired records. Then you know that any records returned meet the criteria.
    Paul

Posting Permissions

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