I want to step through a mailbox, and for each mail item open two forms at the same time (one showing data from an attachment in the the mail item, and the other showing data from a table). I want to be able to paste (by hand) data from the mail-data form to the table-data form, and then close the forms and move on to the next mail item. I can arrange the stepping by making one of the two forms modal, but then I can't paste to/from the non-modal form. If neither of the forms are modal, they both open with the first mail item, but the programme loops all the way through all the other mail items.
Code:
For Each Item In MyItems
If (Left(Item.Subject, 22) = "Afhandeling toezegging") Then
priToezegging_i = Val(Mid(Item.Subject, 23))
Me.Repaint
MyFileName = pubHulpbestandenPad & "Toezegging" & Format(pubAuditor_i, "00")
For Each MyAttachment In Item.Attachments
If Right(MyAttachment.FileName, 5) = ".xlsm" Then
MyFileName = MyFileName & ".xlsm"
If Dir(MyFileName) <> "" Then
SetAttr MyFileName, vbNormal
On Error GoTo ExcelError
Killer: Kill MyFileName
On Error GoTo 0
End If
MyAttachment.SaveAsFile MyFileName
ReadOneSpreadsheet (MyFileName)
End If
Next MyAttachment
Me.Repaint
End If
Next Item
Code:
Private Sub ReadOneSpreadsheet(MyFileName)
Dim MijnObjXL As Object
Dim MijnObjWkb As Object
Dim MijnObjSht As Object
Dim MijnDatumGereed As String, MijnAanpassing As String, MijnOpenArgs As String
'Set object variables
Set MijnObjXL = New Excel.Application
'MijnObjXL.Visible = True
Set MijnObjWkb = MijnObjXL.Workbooks.Open(MyFileName)
Set MijnObjSht = MijnObjWkb.Worksheets(1)
MijnObjSht.Activate
'Read data from the spreadsheet...
pubTekst1 = MijnObjSht.Cells(16, 4) 'these threee are for the form showing data from the spreadsheet
pubTekst2 = MijnObjSht.Cells(17, 4)
pubNummer2_i = priToezegging_i
MijnOpenArgs = priToezegging_i & ",0,0,0,0,0,0,0,'2013-01-01'"
DoCmd.Hourglass False
DoCmd.OpenForm "frmToezeggingAfhandelenen", , , , , acWindowNormal 'data from the spreadsheet
DoCmd.OpenForm "frmToezeggingenBladeren", , , , , acWindowNormal, MijnOpenArgs 'data from the table
DoCmd.Hourglass True
MijnObjWkb.Close savechanges:=False 'Close the file
Set MijnObjSht = Nothing 'Clear the object references
Set MijnObjWkb = Nothing
MijnObjXL.Quit 'Quit Excel
Set MijnObjXL = Nothing
End Sub