Probably isn't the best written routine you have read Rob...
When I use the debugger step-by-step, the error never appears, so I never know where it happens.
Thanks in advance, for your help!
Private Sub PaperReceivedEmail_Click()
On Error GoTo Err_PaperReceivedEmail_Click
Dim Text_email As String
Dim Message As Integer
Dim action_aux As Integer
'checks if the submitting author has an e-mail
If IsNull(Me.[E-mail]) Then
Message = MsgBox("This person hasn't an e-mail address", 0, "Warning")
GoTo Exit_PaperReceivedEmail_Click
End If
'sets the flag for paper received and date of receiveing
Me![FlagPaperReceived] = True
Me!DatePaperReceived = Date
Me!Current_Action = 11
Text_email = "Dear " & Me.[CallTerm] & vbCrLf & "Text test" & vbCrLf & "Best wishes" & vbCrLf & "Valerie Belton"
'sends e-mail
Call SendEmail("test paper received e-mail", Text_email, Me.[E-mail])
'creates a record in paper history about the e-mail
If IsNull(Me!NumRevisionsPaperRevise) Then
action_aux = 0
Else
action_aux = Me!NumRevisionsPaperRevise
End If
Call CmdAddRecord(Me.Paper_Record, 11, "e-mail sent to author: new paper received", action_aux)
Exit_PaperReceivedEmail_Click:
Exit Sub
Err_PaperReceivedEmail_Click:
MsgBox Err.Description
Resume Exit_PaperReceivedEmail_Click
End Sub
'''''''''''''''''''''''''''''''''''''''''''''
Public Sub SendEmail(StrSubject As String, StrBody As String, StrTo As String)
Dim NameSpace As Object
Dim EmailSend As Outlook.MailItem
Dim EmailApp As Object
Set EmailApp = CreateObject("Outlook.Application") 'using the outlook object
Set NameSpace = EmailApp.GetNamespace("MAPI")
Set EmailSend = EmailApp.CreateItem(0)
EmailSend.Subject = StrSubject
EmailSend.Body = StrBody
EmailSend.Recipients.Add (StrTo) 'add the recipient
EmailSend.Display 'display the email
' EmailSend.Send 'send the email
Set EmailApp = Nothing
Set EmailSend = Nothing
End Sub
'''''''''''''''''''''''''''''''''''''
Public Sub CmdAddRecord(PaperRecNo As Integer, Action_Num As Integer, Descr_Act As String, RevNo As Integer)
Dim HistoryTable As DAO.Recordset
'Open up a new record in the table [History New] and sets the values in its fields
Set HistoryTable = CurrentDb.OpenRecordset("History New")
HistoryTable.AddNew
HistoryTable!PaperID = PaperRecNo
HistoryTable!Action = Action_Num
HistoryTable!Description = Descr_Act
HistoryTable!RevisionNo = RevNo
HistoryTable!Date = Date
HistoryTable.Update
Set HistoryTable = Nothing
Forms![Paper].Refresh
End Sub