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 woul be great.
Private Sub Command42_Click()
DoCmd.SetWarnings False
On Error GoTo Err_Command50_Click
DoCmd.OpenReport "Account Details", acViewPreview, , , acWindowNormal, ""
Do
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]![Schlüter Elearning Account Details]!, , , "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 Null
Exit_Command50_Click:
Exit Sub
Err_Command50_Click:
MsgBox Err.Description
Resume Exit_Command50_Click
DoCmd.SetWarnings True
End Sub
Private Sub Command42_Click()
DoCmd.SetWarnings False
On Error GoTo Err_Command50_Click
DoCmd.OpenReport "Account Details", acViewPreview, , , acWindowNormal, ""
Do
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]![Schlüter Elearning Account Details]!, , , "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 Null
Exit_Command50_Click:
Exit Sub
Err_Command50_Click:
MsgBox Err.Description
Resume Exit_Command50_Click
DoCmd.SetWarnings True
End Sub