Connecting Tech Pros Worldwide Help | Site Map

Email Addresses - Ignore if null

Newbie
 
Join Date: Oct 2009
Posts: 4
#1: 3 Weeks Ago
Ok, so i am using this code (see below) to open up a new email message with all my listed clients e-mail addresses in the bcc field.

Pleblem is some of the clients do not have an email address so it comes up with an error.
How do i get Access to ignore these blank fields, where there are no email addresses entered and use the ones that are entered?

Code:
Expand|Select|Wrap|Line Numbers
  1. Private Sub Command12_Click()
  2.  
  3.  
  4.     Dim cn As ADODB.Connection
  5.     Dim rs As ADODB.Recordset
  6.     Dim strEmail As String
  7.  
  8.     Set cn = CurrentProject.Connection
  9.     Set rs = New ADODB.Recordset
  10.  
  11.     rs.Open "CustomerT", cn
  12.  
  13.     With rs
  14.         Do While Not .EOF
  15.  
  16.             strEmail = strEmail & .Fields("Email") & ";"
  17.             .MoveNext
  18.     Loop
  19.         .Close
  20.     End With
  21.  
  22.  
  23. On Error GoTo Err_Command12_Click
  24.  
  25.     DoCmd.SendObject _
  26.     , _
  27.     , _
  28.     , _
  29.     , _
  30.     , _
  31.     ("" & strEmail), _
  32.     , _
  33.     , _
  34.     True
  35.  
  36. Exit_Command12_Click:
  37.     Exit Sub
  38.  
  39. Err_Command12_Click:
  40.     MsgBox Err.Description
  41.  
  42.     Resume Exit_Command12_Click
  43.  
  44. End Sub
Thanks
best answer - posted by ajalwaysus
I have one foot out the door, but here is a quick stab, refine your connection to only those who have email addresses.

Code:
Expand|Select|Wrap|Line Numbers
  1. rs.Open "SELECT * FROM CustomerT WHERE Email Is Not Null", cn
Hope this works.

-AJ
Expert
 
Join Date: Jul 2009
Location: KY
Posts: 244
#2: 3 Weeks Ago

re: Email Addresses - Ignore if null


I have one foot out the door, but here is a quick stab, refine your connection to only those who have email addresses.

Code:
Expand|Select|Wrap|Line Numbers
  1. rs.Open "SELECT * FROM CustomerT WHERE Email Is Not Null", cn
Hope this works.

-AJ
Newbie
 
Join Date: Oct 2009
Posts: 4
#3: 3 Weeks Ago

re: Email Addresses - Ignore if null


Thank you so much. Works perfectly.

You are a Hero!
Cheers
Reply

Tags
access, if isnull, ignore blank field, vba