Working with Arrays

G

Guest

I am using an Array to pass E-Mail addresses to Lotus Notes. The number of E-Mail addresses depends on the results of a query and hence I have to have an Array that may be bigger than the number of E-Mail addresses. The code I'm using to generate the Array is below:-

intCounter = rstEmailAddress.RecordCount

Dim arrSendto(1 To 25) As String

rstEmailAddress.MoveFirst

Do While intCounter <> 0
arrSendto(intCounter) = rstEmailAddress!fldEMail
intCounter = intCounter - 1
rstEmailAddress.MoveNext
Loop

When I pass this to Lotus Notes it tries to send an E-Mail to:-

(e-mail address removed), (e-mail address removed), (e-mail address removed), , , , , , , , , , , , , , , , , , , , , ,

How do I limit the length of my Array dependent on the value of rstEmailAddress.RecordCount.

All help gratefully received.

Andy W
 
N

Nick Coe \(UK\)

Andy,

Dim the array as dynamic and redim it as you go don't forget
the Preserve else you'll have some trouble...:

This is air code - not tested

**********************
Dim arrSendto() as string

intCounter = rstEmailAddress.RecordCount

ReDim arrSendto(0) As String

rstEmailAddress.MoveFirst

Do While intCounter <> 0
arrSendto(UBound(arrSendto)) =
rstEmailAddress!fldEMail
ReDim Preserve arrSendto(UBound(arrSendto) +
1)
intCounter = intCounter - 1
rstEmailAddress.MoveNext
Loop

You may or may not end up with a blank in the array at the
end . From habit I tend to use for next loops and save Do
Loops just for recordsets.

--
Nick Coe (UK)
www.alphacos.co.uk

---

"captain747480" <[email protected]>
wrote in message
I am using an Array to pass E-Mail addresses to Lotus
Notes. The number of E-Mail addresses depends on the results
of a query and hence I have to have an Array that may be
bigger than the number of E-Mail addresses. The code I'm
using to generate the Array is below:-
intCounter = rstEmailAddress.RecordCount

Dim arrSendto(1 To 25) As String

rstEmailAddress.MoveFirst

Do While intCounter <> 0
arrSendto(intCounter) = rstEmailAddress!fldEMail
intCounter = intCounter - 1
rstEmailAddress.MoveNext
Loop

When I pass this to Lotus Notes it tries to send an E-Mail to:-

(e-mail address removed), (e-mail address removed), (e-mail address removed), , ,
, , , , , , , , , , , , , , , , , , ,
How do I limit the length of my Array dependent on the
value of rstEmailAddress.RecordCount.
 
A

Andy Williams

Cheers Nick

I'll try it on Monday.

Nick Coe (UK) said:
Andy,

Dim the array as dynamic and redim it as you go don't forget
the Preserve else you'll have some trouble...:

This is air code - not tested

**********************
Dim arrSendto() as string

intCounter = rstEmailAddress.RecordCount

ReDim arrSendto(0) As String

rstEmailAddress.MoveFirst

Do While intCounter <> 0
arrSendto(UBound(arrSendto)) =
rstEmailAddress!fldEMail
ReDim Preserve arrSendto(UBound(arrSendto) +
1)
intCounter = intCounter - 1
rstEmailAddress.MoveNext
Loop

You may or may not end up with a blank in the array at the
end . From habit I tend to use for next loops and save Do
Loops just for recordsets.

--
Nick Coe (UK)
www.alphacos.co.uk

---

"captain747480" <[email protected]>
wrote in message

Notes. The number of E-Mail addresses depends on the results
of a query and hence I have to have an Array that may be
bigger than the number of E-Mail addresses. The code I'm
using to generate the Array is below:-
, , , , , , , , , , , , , , , , , , ,
value of rstEmailAddress.RecordCount.
 
A

Albert D. Kallal

Try using getrows

Dim vEmail() As Variant

Dim rst As DAO.Recordset

Set rst = CurrentDb.OpenRecordset("test1")
rst.MoveLast
rst.MoveFirst
vEmail = rst.GetRows(rst.RecordCount)

Dim i As Integer

For i = 0 To UBound(vEmail, 1)
Debug.Print vEmail(0, i)
Next i
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top