Click here to Skip to main content
15,887,267 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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 ...


VB
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 the E:Mail it as I have finished with it, but I am getting this error 91 ... it seems to have lost the link to the E:Mail



VB
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 ...

What I have tried:

Searched the web, asked on an Outlook specific forum.
Posted
Updated 25-Jan-18 2:33am
Comments
CHill60 25-Jan-18 7:32am    
Which is the null object? SubFolder or Items(EmailNo). I can't see where you define SubFolder at all (or did you mean it to be SubFolder2?)
Gary Heath 25-Jan-18 8:32am    
Well spotted CHill60 ... I knew it had to be something simple / stupid but I've looked at it for 2 days straight and couldn't see it !!! Thank you, doh, I feel a right Klutz now !!!

1 solution

CHill60's comment above is the answer ... sometimes you just need a fresh set of eyes !!!
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900