选择表数据到数组 - 只提取一行 [英] Selecting table data to array - Only one row fetched
问题描述
我正在尝试从表 EmailList
中获取数据并将其放入一个数组中,该数组将被传递到 Outlook 电子邮件消息的收件人:"字段(电子邮件的脚本是制成).我计划使用 Join()
函数将数组组合成一个字符串,如下所示:Join(varEmailList, "; ")
.
I am attempting to fetch data from a table EmailList
and place it into an array, which will be passed to the "To:" field of an outlook email message (the script for the email is made). I plan on using the Join()
function to combine the array into a string as so: Join(varEmailList, "; ")
.
我的代码:
Private Sub Propose_Click()
Dim MyDB As DAO.Database
Dim rstEmails As DAO.Recordset
Dim varEmails() As Variant
Dim intRowNum As Integer
Dim intColNum As Integer
Set MyDB = CurrentDb
Set rstEmails = MyDB.OpenRecordset("select email from EmailList", dbOpenSnapshot)
'Let's retrieve ALL Rows in the rstEmails Recordset
varEmails = rstEmails.GetRows()
MsgBox ("Number of Fields Retrieved: " & UBound(varEmails, 1) + 1)
rstEmails.Close
Set rstEmails = Nothing
End Sub
我遇到的问题是代码只找到了一条记录,一次至少应该有 10 条记录.
The issue I am having is that only one record is being found by the code, where there should be at least 10 at a time.
推荐答案
DAO.Recordset.GetRows
方法返回的行不会超过一行,除非您明确告诉它返回更多行.
The DAO.Recordset.GetRows
method returns no more than one row unless you explicitly tell it to return more.
要求 GetRows
检索所有行:
'Let's retrieve ALL Rows in the rstEmails Recordset
'varEmails = rstEmails.GetRows()
With rstEmails
.MoveLast
.MoveFirst
varEmails = .GetRows(.RecordCount)
.Close
End With
这是另一个问题......
Here is another issue ...
MsgBox ("Number of Fields Retrieved: " & UBound(varEmails, 1) + 1)
该数组的第一个维度是字段——在本例中只有一个.第二个维度具有这些字段的值:
The first dimension of that array is the fields --- in this case only one. The second dimension has the values of those fields:
MsgBox ("Number of Fields Retrieved: " & UBound(varEmails, 2) + 1)
这篇关于选择表数据到数组 - 只提取一行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!