Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Loop Stops at two

Status
Not open for further replies.

Ammodog

Technical User
Dec 13, 2002
97
0
0
US
I have a Table tblMsgBank that has an LoginID and A Message field. I have a function that when it is called from a command button on a form is supposed to send all of the messages but for some reason it is only sending out one or two of the messages. Does anyone have an Idea Why?

Here is an example of the code:

Function Send

Dim rst as DAO.Recordset
Dim i as integer

'create a recordset from your table
Set rst = CurrentDb.OpenRecordset("tblMsgBank")

'create a counter for the loop (i)
'the index starts at 0 for the 1st record
'Start the loop
With rst
For i = 0 to .Recordcount - 1
Shell ("net send " & !LoginID & " " & !Message & "")
.MoveNext
Next i
End With
rst.Close
set rst = Nothing

End Function

Christopher Abney
"There is no limit to the good you can do if you dont care who gets the credit"
[Afro]
 
Instead of using a loop like that, try using

do while not rst.eof
'code
rst.movenext
loop

or was there a specific reason you've chosen the style of loop you have?
 
sorry mised a line :)


rst.movefirst
do while not rst.eof
'code
rst.movenext
loop
 
I think the RecordCount propert for DAO Recordsets (unlike ADO) only count the number of accessed records not the total number of records. To handle this just put a MoveLast and MoveFirst before you start your loop.

JHall
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top