invalid use of null and error on click

james_IT

Registered User.
Local time
Today, 20:55
Joined
Jul 5, 2006
Messages
208
Hi guys

probably pretty straight forward but cant seem to get it going...

i have a command button to click to send an email to the email address in a field. it works great unless the user has not entered anything into the textbox. and im getting an error if the text box has normal text in it (i dont want to make the field set to hyperlinks or emails only as some users will use this for a second telephone number).

Once the user clicks the command button how can i get access to check if the text box has a valid email address then proceed if so, otherwise ignore the click with no error??

Private Sub Command67_Click()
Dim strPath As String

strPath = Me.PurchaserContact2

If InStr(1, strPath, "@", vbTextCompare) > 0 Then
strPath = "MailTo:" & strPath

End If

Application.FollowHyperlink strPath
End Sub

TIA
 
Code:
Private Sub Command67_Click()
Dim strPath As String

strPath = Me.PurchaserContact2

If InStr(1, strPath, "@", vbTextCompare) > 0 Then
    strPath = "MailTo:" & strPath
    Application.FollowHyperlink strPath

End If

End Sub

Move the application.FollowHyperlink inside the if-block, so it only works on valid emails

JR
 
Code:
Private Sub Command67_Click()
Dim strPath As String

strPath = Me.PurchaserContact2

If InStr(1, strPath, "@", vbTextCompare) > 0 Then
    strPath = "MailTo:" & strPath
    Application.FollowHyperlink strPath

End If

End Sub

Move the application.FollowHyperlink inside the if-block, so it only works on valid emails
JR


thanks. that solves the problem of if its not a valid email but i still get the use of not null error...?
 
Code:
Private Sub Command67_Click()
Dim strPath As String

If Len(Me.PurchaserContact2 & "" ) > 0 Then
   strPath = Me.PurchaserContact2
Else
   Exit Sub
End If

If InStr(1, strPath, "@", vbTextCompare) > 0 Then
    strPath = "MailTo:" & strPath
    Application.FollowHyperlink strPath

End If

End Sub

Add a test for Null on PurchaserContact2, if Null exit sub

JR
 
Thanks matey

worked great! I changed it slightly so it worked with an error message if the button was pressed without a valid email or was null:

Code:
Private Sub Command67_Click()
Dim strPath As String

If Len(Me.PurchaserContact2 & "") > 0 Then
   strPath = Me.PurchaserContact2
Else
   MsgBox "No email entered", , Error
   Exit Sub
End If

If InStr(1, strPath, "@", vbTextCompare) > 0 Then
    strPath = "MailTo:" & strPath
    Application.FollowHyperlink strPath
    Else
       MsgBox "No email entered", , Error
   Exit Sub

End If



End Sub

Thanks Again!!
 

Users who are viewing this thread

Back
Top Bottom