473,387 Members | 1,515 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Tried to add onto this code but I'm a useless noob... :(

1
Hello,

I have no knowledge of Visual Basic to be honest; The comment at the end of the code shows where I pinched the code from. All works apart for my first "null" section that I tried to add, if someone could explain why this doesn't work that would be great.

Site wouldn't let me explain issue further as apparently my info was marked as "spam"

Many thanks in advance,
Jordan.


Expand|Select|Wrap|Line Numbers
  1. Private Sub Send_Email_Button_Click()
  2. If InStr([E-Mail], "") = Null Then
  3.     MsgBox "Please Enter a Valid E-mail Address"
  4.     Exit Sub
  5. End If
  6.     If InStr([E-Mail], "@") = False Then
  7.     MsgBox "The email address '" & [E-Mail] & "' does not appear to be a valid address"
  8.     Exit Sub
  9. Else
  10. Application.FollowHyperlink "Mailto:" & [E-Mail]
  11. ' https://www.experts-exchange.com/questions/21474709/MAILTO-Function-In-MS-Access.html
  12. End If
  13. End Sub
  14.  
Sep 17 '18 #1
1 1451
PhilOfWalton
1,430 Expert 1GB
Hi Jordan

Nice to have you join Bytes.

The code that you need is nearly right, what you need is

Expand|Select|Wrap|Line Numbers
  1.     If IsNull(E-Mail) Then
  2.         MsgBox "Please Enter a Valid E-mail Address"
  3.         Exit Sub
  4.     End If
  5.     .....
A more thorough check is this
Expand|Select|Wrap|Line Numbers
  1. Public Function IE-MailAddress(ByVal E-Mail As String, _
  2.     Optional ByRef sReason As String) As Boolean
  3.  
  4.     'If False is returned, the reason for its failure will be passed back into the optional reason string.
  5.     'IsValid = IE-MailAddress("karl@karlmoore.com", InvalidReason)
  6.     'MsgBox "Invalid mail address, the reason given is: " & InvalidReason
  7.  
  8.     Dim nCharacter As Integer
  9.     Dim sBuffer As String
  10.  
  11.     E-Mail = Trim(E-Mail)
  12.  
  13.     If Len(E-Mail) < 8 Then
  14.         sReason = "Too short"
  15.         Exit Function
  16.     End If
  17.  
  18.     If LCase(Right(E-Mail, 1)) Like "[a-z]" Then
  19.         GoTo CheckAt
  20.     End If
  21.     sReason = "Illegal character at end"        ' Check for '.' etc at end
  22.     Exit Function
  23.  
  24. CheckAt:
  25.     If InStr(E-Mail, "@") = 0 Then
  26.         sReason = "Missing the @"
  27.         Exit Function
  28.     End If
  29.  
  30.     If InStr(InStr(E-Mail, "@") + 1, E-Mail, "@") <> 0 Then
  31.         sReason = "Too many @"
  32.         Exit Function
  33.     End If
  34.  
  35.     If InStr(E-Mail, ".") = 0 Then
  36.         sReason = "Missing the period"
  37.         Exit Function
  38.     End If
  39.  
  40.     If InStr(E-Mail, "@") = 1 Or InStr(E-Mail, "@") = Len(E-Mail) Or _
  41.         InStr(E-Mail, ".") = 1 Or InStr(E-Mail, ".") = Len(E-Mail) Then
  42.         sReason = "Invalid format"
  43.         Exit Function
  44.     End If
  45.  
  46.     For nCharacter = 1 To Len(E-Mail)
  47.         sBuffer = Mid$(E-Mail, nCharacter, 1)
  48.         If Not (LCase(sBuffer) Like "[a-z]" Or sBuffer = "@" Or _
  49.         sBuffer = "." Or sBuffer = "-" Or sBuffer = "_" Or IsNumeric(sBuffer)) Then
  50.              sReason = "Invalid character"
  51.              Exit Function
  52.         End If
  53.     Next nCharacter
  54.  
  55.     nCharacter = 0
  56.  
  57.     On Error Resume Next
  58.  
  59.     sBuffer = Right(E-Mail, 4)
  60.     If InStr(sBuffer, ".") = 0 Then GoTo TooLong:
  61.     If Left(sBuffer, 1) = "." Then sBuffer = Right(sBuffer, 3)
  62.     If Left(Right(sBuffer, 3), 1) = "." Then sBuffer = Right(sBuffer, 2)
  63.     If Left(Right(sBuffer, 2), 1) = "." Then sBuffer = Right(sBuffer, 1)
  64.  
  65.     If Len(sBuffer) < 2 Then
  66.         sReason = "Suffix too short"
  67.         Exit Function
  68.     End If
  69.  
  70. TooLong:
  71.    If Len(sBuffer) > 3 Then
  72.       sReason = "Suffix too long"
  73.       Exit Function
  74.    End If
  75.  
  76.    sReason = Empty                      ' Dropped through to here, so email address OK
  77.    IE-MailAddress = True
  78.  
  79. End Function
I think if you read it, it is fairly obvious what checks it makes.

Phil
Sep 17 '18 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

8
by: Ronald O. Christian | last post by:
One of the benefits of coding in php is that a user can't view your actual php source, only the html it produces. Are there reasonably simple techniques to avoid having the html scooped also? ...
7
by: Mathew Hill | last post by:
I am a beginner to the more technical aspects of Microsoft Access (2000) and was wondering if any one can help. I have 3 buttons on a form which add, delete and search for a record. However, when I...
7
by: Ray Mitchell | last post by:
Hello, I realize that the source code for vsscanf is available from several sources, such as GNU. However, all such source code I've found so far is filled with cryptic (to me) #ifdefs, system...
5
by: Nadav | last post by:
Hi, Introduction: ************************************************************ I am working on a project that should encrypt PE files ( Portable executable ), this require me to inject some...
4
by: Nevyn Twyll | last post by:
Is there any way I can use a code-behind event (like a btn_Click event) to write some javascript into the Response? I was thinking of using Response.Write() to write the following code into the...
4
by: bennett | last post by:
How can I do a loop from 1 to 5, where on line 1 I print 1 space followed by a button, on line 2 I print 2 spaces followed by a button, on line 3 I print 3 spaces followed by a button, etc.? I...
16
by: LP | last post by:
Hello, I am trying to use .NET with Excel. I installed Office 2003 and selected ..NET programming suport option, so it installed all those PIA, as MS sugests. But I can not find a way to destroy...
1
by: djs1979 | last post by:
Hello, First time "designer" here. I've mostly used CoffeeCup Vis Designer (a WYSIWYG prog for those unfamiliar with it), and dropped in some code by hand here and there. My problem is with the...
5
by: maehhheeyy | last post by:
I want to add a timeout so that when I pull out my gps from my serial port, it would wait for a bit then loop and then see if it's there. I also want to add a print statement saying that there is...
15
by: Martin Lang | last post by:
Hi All, Thanks for reading this :) I have a form A that consists of a main form A and a sub form A. In sub form A, I have a field which I can double click. Then, Main form B opens up with a...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.