I have lost some programs so am trying to recreate them from old versions, the problem I have is that I coded this stuff many years ago and can't remember how it all works now, so perhaps one of you can point me in the right direction ...
This is where I decide what type of attachment is coming in so that I can decide what to do with it ...
Code:
NoOfLeagues = NOLindex
Set Ns = GetNamespace("MAPI")
Set Inbox = Ns.GetDefaultFolder(olFolderInbox)
Set SubFolder1 = GetFolder("\\Gary Outlook 2016\Kickabout\Attachments\")
Set SubFolder2 = GetFolder("\\Gary Outlook 2016\Kickabout\Attachments\Unknown")
NoOfEMails = SubFolder1.Items.Count
If NoOfEMails = 0 Then
Exit Sub
End If
KApath = "K:\"
AtmtNo = 0
ErrorNo = 0
MyKIKtxtCount = 0
For EMailNo = NoOfEMails To 1 Step -1
Set EMail = SubFolder1.Items(EMailNo)
KIKcount = 0
TXTcount = 0
MySkip = False
For Each Atmt In EMail.Attachments
KAfiletype = Right(Atmt.FileName, 3)
Select Case KAfiletype
Case Is = "TXT"
Call Validate_TXT
I then process the TXT file and I want to delete it as I have finished with it, but I am getting this error 91 ...
Code:
Sub Validate_TXT()
Atmt.SaveAsFile KApath & "Despatch Schedule/DESPATCH SCHEDULE.TXT"
Set KA_DB = New ADODB.Connection
Set KA_RS_Leagues = New ADODB.Recordset
Set KA_Com = New ADODB.Command
KA_DB.Open "Provider=SQLOLEDB;Server=GARYSPC\SQLEXPRESS;Database=KADB; Trusted_Connection=yes"
Set KA_Com.ActiveConnection = KA_DB
MyFileNum = FreeFile()
Open KApath & "Despatch Schedule\DESPATCH SCHEDULE.TXT" For Input As #MyFileNum
MyFileNum2 = FreeFile()
Open KApath & "Despatch Schedule\DESPATCH SCHEDULE Edited.TXT" For Output As #MyFileNum2
Do While Not EOF(MyFileNum)
Input #MyFileNum, MyScheduleData
DataWanted = False
Call CheckDSdata
If DataWanted = True Then
Print #MyFileNum2, MyScheduleData
End If
Loop
Close #MyFileNum
Close #MyFileNum2
SubFolder.Items(EMailNo).Delete <<< This fails with Error Code 91, Object variable or With block variable not set.
End Sub
Any help greatly appreciated ...