Access VBA - 'On Error' Send Email Help

Status
Not open for further replies.

Cjdash

New Member
Joined
Jun 1, 2018
Messages
7
Hi,

I have the below code that picks up a file based on the contents of a Excel range. However, there will be occasions where a file won't be present. On these occasions I want the code to ping an email to me to let me know. As it stands, the below is sending me 3 emails rather than 1, can anyone help?

Code:
Function ImportTLogAuto()


    DoCmd.SetWarnings False
    
    DoCmd.RunSQL "DELETE FROM TLog"


    Dim objDialog As Object
    Dim varFile As Variant
    Dim strsql As String


    Dim xlApp As Excel.Application
    Dim xlWB As Excel.Workbook
    Dim xlSheet As Excel.Worksheet


    Set xlApp = New Excel.Application
With xlApp
    Set xlWB = .Workbooks.Open("C:\Program Files\Morning Imports.xlsm", , False)
    Set xlSheet = xlWB.Worksheets("PickUp") 'Name of tab you want to select from
End With
 
    varFile = xlSheet.Range("D9")
    
On Error GoTo NoTLog


        DoCmd.TransferText acImportDelim, "TLog Import", "TLog", varFile


        strsql = "UPDATE TLog SET TLog.Filename = '" & varFile & "' " _
               & "WHERE (((TLog.Filename) Is Null));"


        CurrentDb.Execute strsql


    DoCmd.OpenQuery "Qry_Append_RecordLines"
    DoCmd.OpenQuery "Qry_Append_Record61"


NoTLog:
    Call Error_Email("404 - TLog Not Found")


Resume Next


End Function
 

Excel Facts

Get help while writing formula
Click the italics "fx" icon to the left of the formula bar to open the Functions Arguments dialog. Help is displayed for each argument.
Status
Not open for further replies.

Forum statistics

Threads
1,224,823
Messages
6,181,182
Members
453,020
Latest member
Mohamed Magdi Tawfiq Emam

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top