PDA

View Full Version : Solved: Rst Loop only display first or last record



Trevor
01-24-2008, 01:25 PM
Hi,
I am looping through an Rst to display all the email addresses in a table and it is only displaying the first, last or no record at all depending if I use .MoveFirst, .Moveprevious, .Movelast, .MoveNext
and if I Comment out the move statment the event hangs and have to manualy close access, if I uses .Movelast,.MoveFirst. the event also hangs , If I replace the Do Until .EOF to .BOF I get error no record. Here is my code; please help

Dim loDb As DAO.Database
Dim loRst As DAO.Recordset
Set loDb = CurrentDb
Set loRst = loDb.OpenRecordset("QryUnitEmailAddress")
With loRst
Do Until .EOF
SendToo = .Fields("Email") & ""
.MoveNext
Loop
End With

loRst.Close
Set loRst = Nothing
Set loDb = Nothing
EditMessage = 1
SendTo = SendToo
stSubject = "test"
stBody = "Hello"
DoCmd.SendObject , , acFormatTXT, SendTo, , also, stSubject, stBody, 1
End Sub

akn112
01-24-2008, 01:53 PM
i don't quite understand this line
SendToo = .Fields("Email") & ""

shouldn't it look more like
SendToo = SendToo & .Fields("Email") & "; "

Trevor
01-24-2008, 02:17 PM
the sendto = sendtoo line, I was attempting to store the values then put them in sendto to see if that would fix the problem, since your reply I have changed my code to reflect the ; and removed the sendtoo = sendto and I have ran the code and still I get only the first or last record. here is my updated code;

Dim loDb As DAO.Database
Dim loRst As DAO.Recordset
Set loDb = CurrentDb
Set loRst = loDb.OpenRecordset("QryUnitEmailAddress")
With loRst
Do Until .EOF
SendTo = .Fields("Email") & ";"
.MoveNext
Loop
End With
loRst.Close
Set loRst = Nothing
Set loDb = Nothing
EditMessage = 1
stSubject = "test"
stBody = "Hello"
DoCmd.SendObject , , acFormatTXT, SendTo, , also, stSubject, stBody, 1
End Sub

Trevor
01-24-2008, 02:21 PM
Thanks for your reply (I forgot to type it on my first reply,
and the SendToo = SendToo & .Fields("Email") & "; "
is sendto = .fields("Email" & ";"
the sendto is refering to the sendobject method ware the recipient email address will go in an email ( sendto is the to text field of email)

Trevor
01-24-2008, 02:26 PM
Thanks I did change the sendto = .fields("email") & ";"
to sendto = sendto & .fields ("email" & ";"
but why does sendto witch refers to the to section of an email bet set to itself (Sendto = sendto & .fields ("email") & ";") and the email address rather than (sendto = .fields ("email") & ";" ?
Thanks, Trevor

Trevor
01-24-2008, 02:26 PM
and it does work changing sendto = sendto & .fields ("email") & "';"

akn112
01-25-2008, 09:44 AM
and it does work changing sendto = sendto & .fields ("email") & "';"

Glad to hear its working! mark as solved :thumb

Trevor
01-25-2008, 04:34 PM
how do I mark thread as solved? I've never done it

Carl A
01-25-2008, 04:59 PM
At the Top of the page under Thread Tools Select Solved and apply the change