Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

email to address in textbox control content 1

Status
Not open for further replies.

mustangcoupe

Technical User
Feb 26, 2003
221
0
0
US
Ok, I have the following code it emails fine.

BUT if the control is null then I want it to not create an email.

BUT it executes the code and creates the email as specified in the code with no address in the TO: box.(with stop msg in code I see it go to the exit sub line BUT it still creats the email as in the else statment...)


Code:
Private Sub emailcontact_Click()
Dim hlk As Hyperlink
If IsNull(Me.contactemail) Then
Exit Sub
Else
Set hlk = emailcontact.Hyperlink
hlk.Address = "MailTo:" & Me.contactemail & "?subject=Retlif Job Number " & Forms!job_form.Jobnumber
MsgBox "This will create an email and put " & Me.contactemail & "in the" & vbCrLf & " TO: box YOU must open Outlook and Send Mail or your " & vbCrLf & " email may get placed in your Outbox and net get sent.", vbOKOnly, "Send E-mail TO: " & Me.contactemail
End If
End Sub
 
I found that checking a control for null in that manner doesn't necessarily work so I wrote a little function that will check if a control is empty.
-------------------------------------------------------
Function IsSomethingInControl(MyControl As Control) As Integer
IsSomethingInControl = True
If IsNull(MyControl) Then
IsSomethingInControl = False
Else
If IsEmpty(MyControl) Then
IsSomethingInControl = False
Else
If MyControl = "" Then
IsSomethingInControl = False
End If
End If
End If
End Function
-------------------------------------------------------

Call it as follows.

dim intReturn as integer
intReturn = IsSomethingInControl(Me.contactemail)
if intReturn = False then
'don't send email
else
'send email
end if
 
Thanks Bob, i will give it a try, It makes sense to run it through a function like that... (and then I can run ALL my isnulls through one function.)
 
ok, changed my code as follows, it hits the message box in the false then statement but still creats the email.

Code:
Private Sub emailcontact_Click()
Dim hlk As Hyperlink
Set hlk = emailcontact.Hyperlink
Dim intReturn As Integer
intReturn = IsSomethingInControl(Me.contactemail)
If intReturn = False Then
   'don't send email
Call MsgBox("Customer's Email is blank.  Email will not be created.", vbInformation, "Email Customer")

Else
   'send email
hlk.Address = "MailTo:" & Me.contactemail & "?subject=Retlif Job Number " & Forms!job_form.Jobnumber
MsgBox "This will create an email and put " & Me.contactemail & "in the" & vbCrLf & " TO: box YOU must open Outlook and Send Mail or your " & vbCrLf & " email may get placed in your Outbox and net get sent.", vbOKOnly, "Send E-mail TO: " & Me.contactemail
End If
End Sub
 
I have never seen both the "if" and "else" sections of a "if...else...end if" get executed. I would suspect the the email is getting generated elsewhere.

As a test, comment out everything in the "else" section. Add a simple msgbox command as shown below:

msgbox "email will get sent"

Run it and see if both the "if" and "else" messages are displayed. Also see if the email is still created even though it has been commented out in the "else" section.
 
Ok, bob good thought, something is funny.... as it still creates the email but the data looks cashed it has not email but the subject line is filled in but not wilt the full information. BUT it does not hit the test messagebox line! so something else is creating it. somewhere.
 
ok, I figured this one out today.... In mu original code I had used a hyperlink... this got hardcoded in the buttons controls and kept attempting to send email even thought there was no email addreess in the text box.

--Todd


TechnicalUser pretending to be a programmer(shhh… the boss doesn’t know yet)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top