I am trying to get the loop within this code to work, as a one off it works fine but I don't know how to make the process run until all records are updated and the report returns a null value? Any help would be great. I am trying to get it to open the report send the e mail, update the record, close the report then open the next report and so on.

Private Sub Command42_Click()D
oCmd.SetWarnings False
On Error GoTo Err_Command50_Click
DoCmd.OpenReport "Account Details", acViewPreview, , , acWindowNormal, ""
Dim notesdb As Object
Dim notesdoc As Object
Dim notesrtf As Object
Dim notessession As Object
Set notessession = CreateObject("Notes.Notessession")
Set notesdb = notessession.GetDatabase("", "")
Call notesdb.OpenMail
Rem make new mail message
Set notesdoc = notesdb.CreateDocument
Call notesdoc.replaceitemvalue("Sendto", "xxxxxx@xxxxx.com")
Call notesdoc.replaceitemvalue("Subject", "Problem Report")
Set notesrtf = notesdoc.createrichtextitem("body")
Call notesrtf.appendtext("Problem Report")
Call notesrtf.addnewline(2)
DoCmd.SendObject acSendReport, "Account Details", acFormatPDF, [Reports]![Account Details]![Email], , , "Account Inactive", "account has been inactive", False
Call notesdoc.Send(False)
Set notessession = Nothing
DoCmd.OpenQuery "UpdateDeactNoteSent", acViewNormal, acEdit
DoCmd.Close acQuery, "UpdateDeactNoteSent", acSaveYes
DoCmd.Close acReport, "Account Details", acSaveYes
Loop Until [Reports]![Account Details]![UserName] Is NullE
Exit SubErr_Command50_Click:
MsgBox Err.Description
Resume Exit_Command50_Click
DoCmd.SetWarnings True
End Sub