Tantrum time ...Run time error91

here is the issue bit (been fine for two years or so )



Set mi = FindSentItem(ID, sentAfter)

Sentstamp = mi.SentOn
' E-mail has been sent
If Not (mi Is Nothing) Then


so its going int runtime error 91 :
Object Variable or with block variable not set
How is Sentstamp declared?

If one way, that error makes sense.
 
it states 15.02 -as the last patch but i don't believe it -
I'll get hold of my network guy ASAP

I might slow down the process and see what happens
 
Code:
Private Sub QuickEmailSend_Click()




    Const bq  As String = "<blockquote>"

    Const bqe  As String = "</blockquote>"

'Dim mi As Outlook.MailItem

'Dim ID As String

'Dim user As String

'Dim sentAfter As Date

'FileName = ID






'###

Dim OL As Outlook.Application

Set OL = New Outlook.Application

  

'Dim user As String


Dim mi As Outlook.MailItem

Dim ID As String

'Dim user As String

Dim sentAfter As Date

filename = ID





user = OL.Session.CurrentUser.Name

'##


user = OL.Session.CurrentUser.Name

Dim Subjectz As String



  

    LetterName = ""

  

    'Me.EmailAccounttoUSe2 = user

   ' If Me.EmailAccounttoUSe2 = "Gary And EU = True Then Me.EMAILAcc = "x"

    'If Me.EmailAccounttoUSe2 = "Gary " And EU = False Then Me.EMAILAcc = "y"


  '###

  'added 21.09.23

'miniories

'EmailAccounttoUSe

'miniories

 If Me.WHOAMI = "gpa" And EU = True Then Me.EMAILAcc = "x"

 If Me.WHOAMI = "gpa" And EU = True Then Me.EmailAccounttoUSe = "x"


 

 'Arc

 

 If Me.WHOAMI = "gpa" And EU = False Then Me.EMAILAcc = "y"

 If Me.WHOAMI = "gpa" And EU = False Then Me.EmailAccounttoUSe = "y"



'Dim Subjectz As String


    Set frm = Forms!websiteimportfrm

    With frm

  

       LetterName = ""

  

  

    If Me.EU = 0 Then

  

    

         Signature = Environ("appdata") & "\Microsoft\Signatures\"

    If Dir(Signature, vbDirectory) <> vbNullString Then

        Signature = Signature & Dir$(Signature & "AISL2016.htm")

    Else:

        Signature = ""

    End If

 

  

  Signature = CreateObject("Scripting.FileSystemObject").GetFile(Signature).OpenAsTextStream(1, -2).ReadAll

   End If

 

 

      If Me.EU = -1 Then

  

    

         Signature = Environ("appdata") & "\Microsoft\Signatures\"

    If Dir(Signature, vbDirectory) <> vbNullString Then

        Signature = Signature & Dir$(Signature & "MIB.htm")

    Else:

        Signature = ""

    End If

 

 

 

  '##

  

  

 

  Signature = CreateObject("Scripting.FileSystemObject").GetFile(Signature).OpenAsTextStream(1, -2).ReadAll


   End If


 If Me.accounttype = "1" Then Subjectz = "Our Reference :-" & " " & ![QuickQuoteno]


 If Me.accounttype = "2" Then Subjectz = "Our Reference :-" & " " & ![QuickQuoteno] & " - " & "(" & ![QuickInsured] & ")"

 

If Me.QuickQuoteno < 24876 Then Subjectz = "Our Reference :-" & " " & ![QuickQuoteno]


Set mi = createNewEmail()

' Generate a unique E-mail id

Randomize

ID = Format(Now(), "yyyymmddhhnnss") & "_" & CInt(1000 * Rnd()) + 1

' Save date and time

sentAfter = Now()

' Change mail item properties


 

    





With mi

    .To = Nz(Me.QuickEmail)

    .Subject = Nz(Subjectz)

    .HTMLBody = " ." & bqe & bqe & Signature

    .Categories = ID

  

     If Me.EU = False Then

.SendUsingAccount = OL.Session.Accounts(1)

 End If

 

   If Me.EU = True Then

.SendUsingAccount = OL.Session.Accounts(2)

 End If

    


 

End With


' Wait until mailitem window has been closed

While MailItemIsOpen(ID)

    DoEvents

Wend

' Try to find item in Sent Items

Set mi = FindSentItem(ID, sentAfter)

 

Sentstamp = mi.SentOn

' E-mail has been sent

If Not (mi Is Nothing) Then


Dim filepathz  As String

Dim filenamez As String

Dim Subjectx As String

Subjectx = mi.Subject


' date time stamp on email

filenamepart1 = Format(Sentstamp, "yyyy mm dd-hhnnss")

filenamepart2 = "- " & Subjectx

filenamepart2 = CleanString(mi.Subject)

filename = filenamepart1 & " " & filenamepart2

user = OL.Session.CurrentUser.Name
'##

user = OL.Session.CurrentUser.Name
Dim Subjectz As String



LetterName = ""

'Me.EmailAccounttoUSe2 = user
' If Me.EmailAccounttoUSe2 = "Gary And EU = True Then Me.EMAILAcc = "x"
'If Me.EmailAccounttoUSe2 = "Gary " And EU = False Then Me.EMAILAcc = "y"

'###
'added 21.09.23
'miniories
'EmailAccounttoUSe
'miniories
If Me.WHOAMI = "gpa" And EU = True Then Me.EMAILAcc = "x"
If Me.WHOAMI = "gpa" And EU = True Then Me.EmailAccounttoUSe = "x"


'Arc

If Me.WHOAMI = "gpa" And EU = False Then Me.EMAILAcc = "y"
If Me.WHOAMI = "gpa" And EU = False Then Me.EmailAccounttoUSe = "y"


'Dim Subjectz As String

Set frm = Forms!websiteimportfrm
With frm

LetterName = ""


If Me.EU = 0 Then


Signature = Environ("appdata") & "\Microsoft\Signatures\"
If Dir(Signature, vbDirectory) <> vbNullString Then
Signature = Signature & Dir$(Signature & "AISL2016.htm")
Else:
Signature = ""
End If


Signature = CreateObject("Scripting.FileSystemObject").GetFile(Signature).OpenAsTextStream(1, -2).ReadAll
End If


If Me.EU = -1 Then


Signature = Environ("appdata") & "\Microsoft\Signatures\"
If Dir(Signature, vbDirectory) <> vbNullString Then
Signature = Signature & Dir$(Signature & "MIB.htm")
Else:
Signature = ""
End If



'##



Signature = CreateObject("Scripting.FileSystemObject").GetFile(Signature).OpenAsTextStream(1, -2).ReadAll

End If

If Me.accounttype = "1" Then Subjectz = "Our Reference :-" & " " & ![QuickQuoteno]

If Me.accounttype = "2" Then Subjectz = "Our Reference :-" & " " & ![QuickQuoteno] & " - " & "(" & ![QuickInsured] & ")"

If Me.QuickQuoteno < 24876 Then Subjectz = "Our Reference :-" & " " & ![QuickQuoteno]

Set mi = createNewEmail()
' Generate a unique E-mail id
Randomize
ID = Format(Now(), "yyyymmddhhnnss") & "_" & CInt(1000 * Rnd()) + 1
' Save date and time
sentAfter = Now()
' Change mail item properties







With mi
.To = Nz(Me.QuickEmail)
.Subject = Nz(Subjectz)
.HTMLBody = " ." & bqe & bqe & Signature
.Categories = ID

If Me.EU = False Then
.SendUsingAccount = OL.Session.Accounts(1)
End If

If Me.EU = True Then
.SendUsingAccount = OL.Session.Accounts(2)
End If



End With

' Wait until mailitem window has been closed
While MailItemIsOpen(ID)
DoEvents
Wend
' Try to find item in Sent Items
Set mi = FindSentItem(ID, sentAfter)

Sentstamp = mi.SentOn
' E-mail has been sent
If Not (mi Is Nothing) Then

Dim filepathz As String
Dim filenamez As String
Dim Subjectx As String
Subjectx = mi.Subject

' date time stamp on email
filenamepart1 = Format(Sentstamp, "yyyy mm dd-hhnnss")
filenamepart2 = "- " & Subjectx
filenamepart2 = CleanString(mi.Subject)
filename = filenamepart1 & " " & filenamepart2

' edit to this form
filepathz = Me.openfolderxx & filenamepart1 & " " & filenamepart2


mi.SaveAs filepathz & " Sent.msg", Outlook.OlSaveAsType.olMSG

' mi.SaveAs filepathz & FileName & " Sent.msg", Outlook.OlSaveAsType.olMSG

End If

End With


ok - but i still don't get why it works for two years and now moans -

but i am chasing our network guys
 
Last edited:
What is the issue with formatting the code? No one want to read that garbage. You are wasting peoples time.
Properly format it if you want people to look at it.
 
I got the coding from
Does not mean you can not use the code tags above </> to post your code and have it cleaned up and properly indented.
 
Private Sub QuickEmailSend_Click()



Const bq As String = "<blockquote>"
Const bqe As String = "</blockquote>"
'Dim mi As Outlook.MailItem
'Dim ID As String
'Dim user As String
'Dim sentAfter As Date
'FileName = ID





'###
Dim OL As Outlook.Application
Set OL = New Outlook.Application

'Dim user As String

Dim mi As Outlook.MailItem
Dim ID As String
'Dim user As String
Dim sentAfter As Date
filename = ID




user = OL.Session.CurrentUser.Name
'##

user = OL.Session.CurrentUser.Name
Dim Subjectz As String



LetterName = ""

'Me.EmailAccounttoUSe2 = user
' If Me.EmailAccounttoUSe2 = "Gary And EU = True Then Me.EMAILAcc = "x"
'If Me.EmailAccounttoUSe2 = "Gary " And EU = False Then Me.EMAILAcc = "y"

'###
'added 21.09.23
'miniories
'EmailAccounttoUSe
'miniories
If Me.WHOAMI = "gpa" And EU = True Then Me.EMAILAcc = "x"
If Me.WHOAMI = "gpa" And EU = True Then Me.EmailAccounttoUSe = "x"


'Arc

If Me.WHOAMI = "gpa" And EU = False Then Me.EMAILAcc = "y"
If Me.WHOAMI = "gpa" And EU = False Then Me.EmailAccounttoUSe = "y"


'Dim Subjectz As String

Set frm = Forms!websiteimportfrm
With frm

LetterName = ""


If Me.EU = 0 Then


Signature = Environ("appdata") & "\Microsoft\Signatures\"
If Dir(Signature, vbDirectory) <> vbNullString Then
Signature = Signature & Dir$(Signature & "AISL2016.htm")
Else:
Signature = ""
End If


Signature = CreateObject("Scripting.FileSystemObject").GetFile(Signature).OpenAsTextStream(1, -2).ReadAll
End If


If Me.EU = -1 Then


Signature = Environ("appdata") & "\Microsoft\Signatures\"
If Dir(Signature, vbDirectory) <> vbNullString Then
Signature = Signature & Dir$(Signature & "MIB.htm")
Else:
Signature = ""
End If



'##



Signature = CreateObject("Scripting.FileSystemObject").GetFile(Signature).OpenAsTextStream(1, -2).ReadAll

End If

If Me.accounttype = "1" Then Subjectz = "Our Reference :-" & " " & ![QuickQuoteno]

If Me.accounttype = "2" Then Subjectz = "Our Reference :-" & " " & ![QuickQuoteno] & " - " & "(" & ![QuickInsured] & ")"

If Me.QuickQuoteno < 24876 Then Subjectz = "Our Reference :-" & " " & ![QuickQuoteno]

Set mi = createNewEmail()
' Generate a unique E-mail id
Randomize
ID = Format(Now(), "yyyymmddhhnnss") & "_" & CInt(1000 * Rnd()) + 1
' Save date and time
sentAfter = Now()
' Change mail item properties







With mi
.To = Nz(Me.QuickEmail)
.Subject = Nz(Subjectz)
.HTMLBody = " ." & bqe & bqe & Signature
.Categories = ID

If Me.EU = False Then
.SendUsingAccount = OL.Session.Accounts(1)
End If

If Me.EU = True Then
.SendUsingAccount = OL.Session.Accounts(2)
End If



End With

' Wait until mailitem window has been closed
While MailItemIsOpen(ID)
DoEvents
Wend
' Try to find item in Sent Items
Set mi = FindSentItem(ID, sentAfter)

Sentstamp = mi.SentOn
' E-mail has been sent
If Not (mi Is Nothing) Then

Dim filepathz As String
Dim filenamez As String
Dim Subjectx As String
Subjectx = mi.Subject

' date time stamp on email
filenamepart1 = Format(Sentstamp, "yyyy mm dd-hhnnss")
filenamepart2 = "- " & Subjectx
filenamepart2 = CleanString(mi.Subject)
filename = filenamepart1 & " " & filenamepart2

' edit to this form
filepathz = Me.openfolderxx & filenamepart1 & " " & filenamepart2


mi.SaveAs filepathz & " Sent.msg", Outlook.OlSaveAsType.olMSG

' mi.SaveAs filepathz & FileName & " Sent.msg", Outlook.OlSaveAsType.olMSG

End If

End With


ok - but i still don't get why it works for two years and now moans -

but i am chasing our network guys
Please use code tags :(
The </> icon.
 
How is Sentstamp declared?

If one way, that error makes sense.
could you expand upon this - as it is this line where its "having an issue" ?

how would you declare it ?

(I am more of a patch it together user tthan an indepth user )
 
is there an issue with new outlook?

"New" Outlook does not respond to VBA because it has abandoned the Component Object Model that VBA uses. I have not seen many reports of people automating New Outlook via any of the normal automation methods. (Admittedly I could have missed seeing them... if any existed.)
 
"New" Outlook does not respond to VBA because it has abandoned the Component Object Model that VBA uses. I have not seen many reports of people automating New Outlook via any of the normal automation methods. (Admittedly I could have missed seeing them... if any existed.)
If I understand it correctly, automating New Outlook would require creating an Add-in, or perhaps the use of JavaScript.
 
If I understand it correctly, automating New Outlook would require creating an Add-in, or perhaps the use of JavaScript.

I would believe that. From what I've heard, New Outlook is supposed to somehow be more web friendly, so Javascript would be in line with that.
 
Private Sub QuickEmailSend_Click()



Const bq As String = "<blockquote>"
Const bqe As String = "</blockquote>"
'Dim mi As Outlook.MailItem
'Dim ID As String
'Dim user As String
'Dim sentAfter As Date
'FileName = ID





'###
Dim OL As Outlook.Application
Set OL = New Outlook.Application

'Dim user As String

Dim mi As Outlook.MailItem
Dim ID As String
'Dim user As String
Dim sentAfter As Date
filename = ID




user = OL.Session.CurrentUser.Name
'##

user = OL.Session.CurrentUser.Name
Dim Subjectz As String



LetterName = ""

'Me.EmailAccounttoUSe2 = user
' If Me.EmailAccounttoUSe2 = "Gary And EU = True Then Me.EMAILAcc = "x"
'If Me.EmailAccounttoUSe2 = "Gary " And EU = False Then Me.EMAILAcc = "y"

'###
'added 21.09.23
'miniories
'EmailAccounttoUSe
'miniories
If Me.WHOAMI = "gpa" And EU = True Then Me.EMAILAcc = "x"
If Me.WHOAMI = "gpa" And EU = True Then Me.EmailAccounttoUSe = "x"


'Arc

If Me.WHOAMI = "gpa" And EU = False Then Me.EMAILAcc = "y"
If Me.WHOAMI = "gpa" And EU = False Then Me.EmailAccounttoUSe = "y"


'Dim Subjectz As String

Set frm = Forms!websiteimportfrm
With frm

LetterName = ""


If Me.EU = 0 Then


Signature = Environ("appdata") & "\Microsoft\Signatures\"
If Dir(Signature, vbDirectory) <> vbNullString Then
Signature = Signature & Dir$(Signature & "AISL2016.htm")
Else:
Signature = ""
End If


Signature = CreateObject("Scripting.FileSystemObject").GetFile(Signature).OpenAsTextStream(1, -2).ReadAll
End If


If Me.EU = -1 Then


Signature = Environ("appdata") & "\Microsoft\Signatures\"
If Dir(Signature, vbDirectory) <> vbNullString Then
Signature = Signature & Dir$(Signature & "MIB.htm")
Else:
Signature = ""
End If



'##



Signature = CreateObject("Scripting.FileSystemObject").GetFile(Signature).OpenAsTextStream(1, -2).ReadAll

End If

If Me.accounttype = "1" Then Subjectz = "Our Reference :-" & " " & ![QuickQuoteno]

If Me.accounttype = "2" Then Subjectz = "Our Reference :-" & " " & ![QuickQuoteno] & " - " & "(" & ![QuickInsured] & ")"

If Me.QuickQuoteno < 24876 Then Subjectz = "Our Reference :-" & " " & ![QuickQuoteno]

Set mi = createNewEmail()
' Generate a unique E-mail id
Randomize
ID = Format(Now(), "yyyymmddhhnnss") & "_" & CInt(1000 * Rnd()) + 1
' Save date and time
sentAfter = Now()
' Change mail item properties







With mi
.To = Nz(Me.QuickEmail)
.Subject = Nz(Subjectz)
.HTMLBody = " ." & bqe & bqe & Signature
.Categories = ID

If Me.EU = False Then
.SendUsingAccount = OL.Session.Accounts(1)
End If

If Me.EU = True Then
.SendUsingAccount = OL.Session.Accounts(2)
End If



End With

' Wait until mailitem window has been closed
While MailItemIsOpen(ID)
DoEvents
Wend
' Try to find item in Sent Items
Set mi = FindSentItem(ID, sentAfter)

Sentstamp = mi.SentOn
' E-mail has been sent
If Not (mi Is Nothing) Then

Dim filepathz As String
Dim filenamez As String
Dim Subjectx As String
Subjectx = mi.Subject

' date time stamp on email
filenamepart1 = Format(Sentstamp, "yyyy mm dd-hhnnss")
filenamepart2 = "- " & Subjectx
filenamepart2 = CleanString(mi.Subject)
filename = filenamepart1 & " " & filenamepart2

' edit to this form
filepathz = Me.openfolderxx & filenamepart1 & " " & filenamepart2


mi.SaveAs filepathz & " Sent.msg", Outlook.OlSaveAsType.olMSG

' mi.SaveAs filepathz & FileName & " Sent.msg", Outlook.OlSaveAsType.olMSG

End If

End With


ok - but i still don't get why it works for two years and now moans -

but i am chasing our network guys
Gets asked to use code tags and just ignores that request.
Let me introduce you to my IL. :cool:
 

Users who are viewing this thread

Back
Top Bottom