email address missing (1 Viewer)

kitty77

Registered User.
Local time
Today, 18:15
Joined
May 27, 2019
Messages
710
I'm using the following code to send an email. But if the email field has no value or is empty the code blows up.
How can I, if the email field is empty have a chance to manually enter a value and have the code continue?

Basically prompt me to enter a value if it's empty...

With MailOutLook
.To = [Memailsent]
' .bcc = ""
.Subject = "Subject"
.Body = "Body" _
' .Send
.Display
End With
 

Gasman

Enthusiastic Amateur
Local time
Today, 23:15
Joined
Sep 21, 2011
Messages
14,231
Should that be Me.EmailSent ?

Regardless, check if it is Null or "" and if so, use InputBox to populate the variable.
 

plog

Banishment Pending
Local time
Today, 17:15
Joined
May 11, 2011
Messages
11,638
Instead of directly using Memailsent in your code, set it to a variable:

str_ToEmail = [Memailsent]

Then test to see if its blank and if so display an input box:


Set the user's input to str_ToEmail. Next I'd at least rudimentarily validate it (minimum 6 characters, has an '@', has a '.' after the '@', etc.) because user's aren't the brightest If it fails validation I'd continue to run the input box and validate it until it passes. Then finally do your email code with str_ToEmail
 

kitty77

Registered User.
Local time
Today, 18:15
Joined
May 27, 2019
Messages
710
Instead of directly using Memailsent in your code, set it to a variable:

str_ToEmail = [Memailsent]

Then test to see if its blank and if so display an input box:


Set the user's input to str_ToEmail. Next I'd at least rudimentarily validate it (minimum 6 characters, has an '@', has a '.' after the '@', etc.) because user's aren't the brightest If it fails validation I'd continue to run the input box and validate it until it passes. Then finally do your email code with str_ToEmail
Any way to get an example using mine and what you suggest?

Thanks!
 

Users who are viewing this thread

Top Bottom