Let’s use a Macro to automate some emails that can make our life so much easier.
Below is Macro that will send an email out to a group or an individual is a certain task is performed. In my case, when ever an Engineering Master is created in Visuals “Manufacturing Window”, it will send an Email notification.
Change the below highlighted fields and save the code.
Dim Pid Dim eng Dim ans If WO_TYPE = "M" Then Pid = InputBox("Enter the Part ID for the new EM", "Part ID") Part_ID = Pid ENGINEERED_BY = USER Set NewMail = CreateObject("CDO.Message") Set mailConfig = CreateObject("CDO.Configuration") ' load all default configurations mailConfig.Load -1 Set fields = mailConfig.fields 'Set All Email Properties With NewMail .Subject = "Your Trigger subject " & pid & " ?" .From = "firstname.lastname@example.org" .To = "YOUR_GROUP_OF_EMAILS_HERE" .CC = "" .BCC = "" .textbody = "Your trigger email message" End With msConfigURL = "http://schemas.microsoft.com/cdo/configuration" With fields 'Enable SSL Authentication .Item(msConfigURL & "/smtpusessl") = True 'Make SMTP authentication Enabled=true (1) .Item(msConfigURL & "/smtpauthenticate") = 1 'Set the SMTP server and port Details 'To get these details you can get on Settings Page of your Gmail Account .Item(msConfigURL & "/smtpserver") = "smtp.gmail.com" .Item(msConfigURL & "/smtpserverport") = 465 .Item(msConfigURL & "/sendusing") = 2 'Set your credentials of your Gmail Account .Item(msConfigURL & "/sendusername") = "YOUR_EMAIL_ADRRESS@GMAIL.COM" .Item(msConfigURL & "/sendpassword") = "YOUR_PASSWORD" 'Update the configuration fields .Update End With NewMail.Configuration = mailConfig NewMail.Send End if
Tip: You can name your Macro whatever you wish to but Visual has a flexibility to call a few Macro based on certain events.
Visuals “OnEvent” Macros:
- OnSave: This will be called right after hit save. This is before the data hits the database.
- OnAfterSave: This is a little different from OnSave. This is run after the data hits the database.
- OnLoad: This fires after the data is loaded in the window.
- OnNew: This fires right after “New” button is clicked.
However, manufacturing window has a some new Marco.
- Sending automatic Emails to your customer when ever a Sales Order is created for them.
- Sending Emails to Employees when there are setup in Visual under employee maintenance. (Same with a new customer added).
- Sending Emails when a Picklist is generated.
Well, the applications are infinite here.