Hi
I'm having problems with a section of code which previously worked but I can't see why it isn't fully executing now. Here's the code:
With the error handling disabled, the code works perfectly until the end of the With block and the email pops up and sends straight away. But, the rest of the code doesn't execute so I can just keep pressing the save button and it keeps sending the same email.
With the error handling it doesn't work at all!
Any help would be greatly appreciated.
Kind regards
A very confused Allison
I'm having problems with a section of code which previously worked but I can't see why it isn't fully executing now. Here's the code:
Code:
Private Sub SaveFirstAuth_Click()
Dim OrgURN As String
Dim GrantURN As String
On Error GoTo ErrorHandler
OrgURN = "Org URN " & Me.OrganisationURN
GrantURN = "Grant URN " & Me.GrantURN
If IsNull(Me.FirstAuthorisation) Then
If IsNull(Me.FirstAuthorisationDate) Then
If IsNull(Me.FinalAuthorisation) Then
GoTo Error
'Email message text
Dim msg As String
msg = "Organisation Name: " & OrganisationName & ",<p>" _
& GrantURN & ",<p>" & "Payment ready for final authorisation."
'Define variables
Dim O As Outlook.Application
Dim M As Outlook.MailItem
'Set variables
Set O = New Outlook.Application
Set M = O.CreateItem(olMailItem)
'Set sender address, text format, recipient, subject and send
With M
.SentOnBehalfOfName = "crtsupport@coalfields-regen.org.uk"
.BodyFormat = olFormatHTML
.HTMLBody = msg
.To = "allison.carr@coalfields-regen.org.uk" 'Me.FinalAuthorisation.Column(1)
.Subject = "Payment for Authorisation"
.Display
.Send
.SaveAs "S:\IT\1 - Testing\Documents\" & OrgURN & "\" & GrantURN & "\" & "Payment Authorised.msg"
End With
Set M = Nothing
Set O = Nothing
'Disable authorisation fields and update payment status
FirstAuthorisation.Enabled = False
FirstAuthorisationDate.Enabled = False
FinalAuthorisation.Enabled = False
Me.PaymentStatus = "Awaiting final authorisation"
Me.SaveFirstAuth.Enabled = False
MsgBox "Payment authorised"
Me.Dirty = False
DoCmd.Close
Exit Sub
ErrorHandler:
Dim msg As String
msg = Err.Number & ":" & Err.Description
MsgBox msg
Error:
MsgBox "Please add first authorisation, date and final authorisation"
End Sub
With the error handling disabled, the code works perfectly until the end of the With block and the email pops up and sends straight away. But, the rest of the code doesn't execute so I can just keep pressing the save button and it keeps sending the same email.
With the error handling it doesn't work at all!
Any help would be greatly appreciated.
Kind regards
A very confused Allison