Been working at some VBA coding to stick behind a BO report. Basically the coding looks at each value for a document variable called "Manager" filters by this value, saves the report and then it's supposed to e-mail it using the document variable called "E-Mail".
The problem i've got is that the way i've structured the coding means that the e-mail value does not correspond to the manager value (I.E: The reports are being e-mailed to the wrong person.
I think that where i'm going wrong is that i'm referencing the <e-mail> variable in the wrong way....
I've attached the code below, any suggestions about possible fixes or even just how to reference a single document variable value in a filtered report that isn't being used to filter the report (so only the current value is being referenced) would be appreciated.
Sub FilterAndExportMail()
Dim mydoc As Document
Dim myrpt As Report
Dim myFilterVar As DocumentVariable
Dim myFilterVar1 As DocumentVariable
Dim i, intNumChoices As Integer
Dim myFilterChoices As Variant
Dim myFilterChoices1 As Variant
Dim strNextValue As String
Dim strNextValue1 As String
Dim Maildb As Object 'the mail database
Dim username As String
Dim maildbname As String
Dim maildoc As Object
Dim attachme As Object
Dim session As Object
Dim embedobject As Object
Dim mytime As String
Dim recipient As String
Dim subject As String
Dim attachment As String
Dim BodyText As String
' Active (open) Document
Set mydoc = ActiveDocument
' Active (with focus) Report
Set myrpt = ActiveReport
' Put your variable (or query object) here
Set myFilterVar = mydoc.DocumentVariables("Manager"
Set myFilterVar1 = mydoc.DocumentVariables("E-Mail"
' find out how many resort values there are
intNumChoices = UBound(myFilterVar.Values(boUniqueValues))
' collect the number of choices in a variant variable
myFilterChoices = myFilterVar.Values(boUniqueValues)
myFilterChoices1 = myFilterVar1.Values(boUniqueValues)
For i = 1 To intNumChoices
' Get the variable value
strNextValue = myFilterChoices(i)
strNextValue1 = myFilterChoices1(i)
' build filter
myrpt.AddComplexFilter myFilterVar, "=<Manager> = " & """" & strNextValue & """"
' recompute the report
myrpt.ForceCompute
strNextValue1 = myFilterChoices1(i)
' now export to desired format, using the filter value as part of the name
myrpt.ExportAsRtf ("F:\MI\Wills Mi\Pfs\Wills Not Signed " & strNextValue & ".rtf"
'this next bit performs the e-mailing
recipient = strNextValue1
subject = "Wills Not Signed Report"
attachment = "F:\MI\Wills Mi\Pfs\Wills Not Signed " & strNextValue & ".rtf"
BodyText = "Diary"
Set session = CreateObject("Notes.NotesSession"
username = session.username
Set Maildb = session.GETDATABASE("", maildbname)
If Maildb.ISOPEN = True Then
Else
Maildb.OPENMAIL
End If
Set maildoc = Maildb.CREATEDOCUMENT
maildoc.Form = "Memo"
maildoc.sendto = recipient
maildoc.subject = subject
maildoc.Body = BodyText
If attachment <> "" Then
Set attachme = maildoc.CREATERICHTEXTITEM("Attachment"
Set embedobject = attachme.embedobject(1454, "", attachment, "Attachment"
End If
maildoc.PostedDate = Now()
maildoc.Send 0, recipient
Set Maildb = Nothing
Set maildoc = Nothing
Set attachme = Nothing
Set session = Nothing
Next i
myrpt.AddComplexFilter myFilterVar, "=(1=1)"
myrpt.ForceCompute
End Sub
The problem i've got is that the way i've structured the coding means that the e-mail value does not correspond to the manager value (I.E: The reports are being e-mailed to the wrong person.
I think that where i'm going wrong is that i'm referencing the <e-mail> variable in the wrong way....
I've attached the code below, any suggestions about possible fixes or even just how to reference a single document variable value in a filtered report that isn't being used to filter the report (so only the current value is being referenced) would be appreciated.
Sub FilterAndExportMail()
Dim mydoc As Document
Dim myrpt As Report
Dim myFilterVar As DocumentVariable
Dim myFilterVar1 As DocumentVariable
Dim i, intNumChoices As Integer
Dim myFilterChoices As Variant
Dim myFilterChoices1 As Variant
Dim strNextValue As String
Dim strNextValue1 As String
Dim Maildb As Object 'the mail database
Dim username As String
Dim maildbname As String
Dim maildoc As Object
Dim attachme As Object
Dim session As Object
Dim embedobject As Object
Dim mytime As String
Dim recipient As String
Dim subject As String
Dim attachment As String
Dim BodyText As String
' Active (open) Document
Set mydoc = ActiveDocument
' Active (with focus) Report
Set myrpt = ActiveReport
' Put your variable (or query object) here
Set myFilterVar = mydoc.DocumentVariables("Manager"

Set myFilterVar1 = mydoc.DocumentVariables("E-Mail"

' find out how many resort values there are
intNumChoices = UBound(myFilterVar.Values(boUniqueValues))
' collect the number of choices in a variant variable
myFilterChoices = myFilterVar.Values(boUniqueValues)
myFilterChoices1 = myFilterVar1.Values(boUniqueValues)
For i = 1 To intNumChoices
' Get the variable value
strNextValue = myFilterChoices(i)
strNextValue1 = myFilterChoices1(i)
' build filter
myrpt.AddComplexFilter myFilterVar, "=<Manager> = " & """" & strNextValue & """"
' recompute the report
myrpt.ForceCompute
strNextValue1 = myFilterChoices1(i)
' now export to desired format, using the filter value as part of the name
myrpt.ExportAsRtf ("F:\MI\Wills Mi\Pfs\Wills Not Signed " & strNextValue & ".rtf"

'this next bit performs the e-mailing
recipient = strNextValue1
subject = "Wills Not Signed Report"
attachment = "F:\MI\Wills Mi\Pfs\Wills Not Signed " & strNextValue & ".rtf"
BodyText = "Diary"
Set session = CreateObject("Notes.NotesSession"

username = session.username
Set Maildb = session.GETDATABASE("", maildbname)
If Maildb.ISOPEN = True Then
Else
Maildb.OPENMAIL
End If
Set maildoc = Maildb.CREATEDOCUMENT
maildoc.Form = "Memo"
maildoc.sendto = recipient
maildoc.subject = subject
maildoc.Body = BodyText
If attachment <> "" Then
Set attachme = maildoc.CREATERICHTEXTITEM("Attachment"

Set embedobject = attachme.embedobject(1454, "", attachment, "Attachment"

End If
maildoc.PostedDate = Now()
maildoc.Send 0, recipient
Set Maildb = Nothing
Set maildoc = Nothing
Set attachme = Nothing
Set session = Nothing
Next i
myrpt.AddComplexFilter myFilterVar, "=(1=1)"
myrpt.ForceCompute
End Sub