cancel
Showing results for 
Search instead for 
Did you mean: 

Automatically add attachments to email

jeanm33
Discoverer
0 Kudos

Hi expert

I want to attach parts to an email by the action of a button in the attachments tab of the email input mask.
I have the following code but I'm having trouble inserting the records into the matrix..


Try 
form=application.Forms.ActiveForm
Dim errMsg As String
Dim nErr As Long

Dim oRec As SAPbobsCom.RecordSet
oRec=company.GetBusinessObject(SAPbobsCOM.BoObjectTypes.BoRecordset)
Dim oATOITM as SAPbobsCOM.Attachments2
oATOITM = company.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oAttachments2)
Dim oDBDataSource As SAPbouiCOM.DBDataSource


Dim bFound As Boolean = False
Dim iNum As Long = 1

Dim oFolder As SAPbouiCOM.Folder
Dim oMatrix as SAPbouiCOM.Matrix
Dim oColumns As SAPbouiCOM.Columns

Dim DocNum as String
Dim nRec as Integer
Dim Qstr as String

Form.freeze(TRUE)

oFolder = Form.Items.Item("11").Specific
oFolder.Select()
oMatrix=Form.Items.Item("10").Specific
oColumns = oMatrix.Columns
nRec=oMatrix.RowCount
DocNum=oColumns.Item("V_0").Cells.Item(1).Specific.Value.toString



oFolder = Form.Items.Item("20").Specific 'Attachments Folder
oFolder.Select()
oMatrix=Form.Items.Item("22").Specific 'Matrix on the folder

Form.freeze(FALSE)

oDBDataSource = Form.DataSources.DBDataSources.Item("ATC1")


Qstr="SELECT Distinct T4.""AbsEntry"" FROM OQUT T0 "
Qstr=Qstr +" INNER JOIN QUT1 T1 on T0.""DocEntry""=T1.""DocEntry"" INNER JOIN OITM T2 ON T1.""ItemCode""=T2.""ItemCode"" "
Qstr=Qstr +" INNER JOIN OITB T3 on T2.""ItmsGrpCod"" = T3.""ItmsGrpCod"" "
Qstr=Qstr + " INNER JOIN ATC1 T4 ON T2.""AtcEntry""=T4.""AbsEntry"" WHERE "
Qstr=Qstr +" T3.""ItmsGrpNam"" in ('Solution','Produit') and T2.""AtcEntry"" >1 and T0.""DocNum""="+DocNum

oRec.DoQuery(Qstr)


oDBDataSource.InsertRecord(oDBDataSource.Size+1) ' this line make an error

WHILE oRec.EOF = False
oATOITM.GetByKey(oRec.Fields.Item(0).Value)
for iNum=0 to oATOITM.Lines.Count-1
oDBDataSource.SetValue("FileName", 0, oATOITM.Lines.FileName) . . .
Next oDBDataSource.InsertRecord(oDBDataSource.Size+1) oRec.MoveNext
END WHILE
oMatrix.LoadFormDataSource()


'Check Error

Call Company.GetLastError(nErr, errMsg)
If (0 <> nErr) Then
application.SetStatusBarMessage ("Found error:" + Cstr(nErr) + "," + errMsg,10,True)
End If

Catch ex as Exception
Application.Messagebox ("Exception:" +ex.Message)
End try


Accepted Solutions (0)

Answers (0)