嗨我是VB和Access的初学者,我想知道每当我拿出While语句时,它会生成一个bug,它不会运行。 我认为while语句设置MyList = MyRec [email],是吗?
但是为什么每当我只更换While语句时 MyList = MyRec [email],它不会编译。
我正在尝试简化将SQL语句放在MyList中的代码 作为MyList = MyRec [email],但我不知道如何...
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
非常感谢!
答案 0 :(得分:0)
while实际上是循环遍历SELECT
语句返回到记录集的所有项目。
While Not MyRec.EOF ' While there are emails still in the recordset
MyList = MyList & ";" & MyRec![email] ' Append the current email to the list
MyRec.MoveNext ' Get the next email in the list
Wend
如果没有While
循环以及对.MoveNext
的调用,您将无法从列表中检索所有电子邮件地址。
有意义吗?