Link to home
Start Free TrialLog in
Avatar of changjia
changjia

asked on

VB script help

Hi Expert:

I have this script that suppose to scan in a txt file and email them to me. The problem is that when the txt file is empty, the script refuses to run.
Could someone help me modify this script so if the txt is empty, it sends out " No record avaiable" in the email body?

Thanks
Const ForReading = 1
Const TriStateUseDefault = -2
 
'Customize these variables
strEmailFrom = "computera@abc.com"
strEmailTo = "andy@abc.com"
strEmailSubject = "Remote access report for computera"
strEmailBody = "Remote access report for computera " & time & "  " & date
strSMTP = "m-a@abc.com"
strAttachment = "c:\remoteaccess.txt"
 
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.OpenTextFile(strAttachment, ForReading, False, TriStateUseDefault)
strEmailBody = strEmailBody & vbCrLf & vbCrLf & objFile.ReadAll 
objFile.Close
 
Set objEmail = CreateObject("CDO.Message")
 
objEmail.From = strEmailFrom
objEmail.To = strEmailTo
objEmail.Subject = strEmailSubject
objEmail.Textbody = strEmailBody
 
objEmail.Configuration.Fields.Item _
    ("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
objEmail.Configuration.Fields.Item _
    ("http://schemas.microsoft.com/cdo/configuration/smtpserver") = _
        strSMTP
objEmail.Configuration.Fields.Item _
    ("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
objEmail.Configuration.Fields.Update
 
objEmail.Send

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of omgang
omgang
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of changjia
changjia

ASKER

Hi guys:

Both of your scripts work!

points shared.

Thanks for the help!!