-1

请解释从我是 VB 新手的代码中获取的这些语句的含义,我们将不胜感激。谢谢。

'Statement

While Not MyRec.EOF  ' Loop trough the table
    MyList = MyList & ";" & MyRec![email]
    MyRec.MoveNext
Wend

MyList = Mid(MyList, 2)



'Below CODE

function GetMailList()
    Dim MyDB As DAO.Database, MyRec As DAO.Recordset, MyList As String
    Set MyDB = CurrentDb
    Set MyRec = MyDB.OpenRecordset("Select email From TableName")

    While Not MyRec.EOF  ' Loop trough the table
        MyList = MyList & ";" & MyRec![email]
        MyRec.MoveNext
    Wend

    MyList = Mid(MyList, 2)

    ' use you code here with the mail list ceated

    MyRec.Close
    MyDB.Close
End Function

谢谢

4

2 回答 2

1

1.创建数据库连接并获取数据

Dim MyDB As DAO.Database, MyRec As DAO.Recordset, MyList As String
Set MyDB = CurrentDb
Set MyRec = MyDB.OpenRecordset("Select email From TableName")

2.当myRec中有未读记录时,循环遍历记录。这里EOF是指End-Of-File

While Not MyRec.EOF  ' Loop trough the table

    MyList = MyList & ";" & MyRec![email]
    'this will append the eMail field to the string

    MyRec.MoveNext
Wend

3. 现在所有的电子邮件已经被连接到字符串(我们有一个分号分隔的电子邮件值),关闭连接和所有

MyRec.Close
MyDB.Close
于 2013-06-08T13:48:15.033 回答
0

这会将 TableName 表中 email 列中的所有值连接成一个用分号分隔的长字符串。

所以在循环结束时,你会有类似的东西:

;address1@something.com;address2@something.com;address3@something.com

请注意,分号在前面,而不是后面,因为连接的编写方式。最后一行通过将字符串替换为从第二个字符开始的自身来去掉第一个分号。

于 2013-06-08T13:45:42.587 回答