send email (1 Viewer)

Nancythomas

Registered User.
Local time
Today, 11:23
Joined
Apr 20, 2010
Messages
59
Hi

I need help again.

I am trying to get the VB script to work but it does not.
Please check and let me known where I am going wrong.

I need to send email to all users from the userID field. The list is in the form.

Attached is the sample db

Appreciate your help
 

Attachments

  • ECTEST1.zip
    68 KB · Views: 68

Gasman

Enthusiastic Amateur
Local time
Today, 18:23
Joined
Sep 21, 2011
Messages
14,046
Firstly, you need Option Explicit at the top of all your modules. I could not find various variables like gDummy ?

You don't say what the problem is, but the code in Red might be the cause.?

HTH
Code:
Private Sub cmdsendemailforMobileNo_Click()
  ''Send Text Messages to the selected PSC Division Employees - Staff Emergency Notification
    '  --------
    Dim oLook As Object
    Dim oMail As Object
    Dim olns As Outlook.NameSpace
    Dim strTO As String
    Dim strMessageBody As String
    Dim strSubject As String
    Dim myDB As DAO.Database
    Dim rst As DAO.Recordset
     
    'Do you even have E-Mail Addressess in the Mailing List Table?
 
    If DCount("[txtUserID]", "frmEmpNoMobile") = 0 Then Exit Sub
    
      [COLOR="Red"]Exit Sub[/COLOR]
      
    Set myDB = CurrentDb
    Set rst = myDB.OpenRecordset("frmEmpNoMobile", dbOpenSnapshot, dbOpenForwardOnly)
     
    Set oLook = CreateObject("Outlook.Application")
    Set olns = oLook.GetNamespace("MAPI")
    Set oMail = oLook.CreateItem(0)
     
   ' Build the Recipient List
    With rst
     Do While Not .EOF
       strTO = strTO & ![txtUserID] & ";"
       .MoveNext
  Loop
  End With
  
    'Remove Trailing ';'
strTO = Left$(strTO, Len(strTO) - 1)
     
    '******************************* USER DEFINED SECTION ********************************
   strMessageBody = "Hi,<br/><br/>" & _
"All PSC work units are required to maintain preparedness for unexpected occurrences as per the Emergency Management (Emergency Relief Centres under the CBD Safety Plan) and Business Continuity Management plans. <br/><br/>" & _
"Communication plans include employee messaging via mobile telephone, by SMS messaging or telephone call. <br/><br/>" & _
"You are receiving this message because we do not have your mobile contact number on our records. <br/><br/>" & _
"Regards <br/>"
    
    strSubject = "Please provide us with your emergency contact number (Mobile Number) [DLM=Sensitive:Personal]"
   oMail.Display
        
    '*************************************************************************************
      
       
 'On Error Resume Next
  
 MsgBox "ERC Message Sent Successfully!", vbOKOnly, "Mail Sent"
     
 Set oMail = Nothing
 Set oLook = Nothing
     
 rst.Close
 Set rst = Nothing
       

End Sub
 

NauticalGent

Ignore List Poster Boy
Local time
Today, 14:23
Joined
Apr 27, 2015
Messages
6,286
Yeah, I’d say that would be problematic!
 

Nancythomas

Registered User.
Local time
Today, 11:23
Joined
Apr 20, 2010
Messages
59
I get the below error

Run time error 3078
Microsoft aaccess database engine cannot find the input table or query.


I need to click the send email and the email should go to all UserIDs
 

Attachments

  • Capture.JPG
    Capture.JPG
    23.5 KB · Views: 56

Gasman

Enthusiastic Amateur
Local time
Today, 18:23
Joined
Sep 21, 2011
Messages
14,046
Well the error message is clear enough.?

Your table/query name starts with "frm".

If that was in my system that would indicate a Form not a query.?
I start my queries with qry and my tables with tbl.

I suspect it is on the Dcount line.

You need to walk through the code with F8 to see the code work line by line..
 

Users who are viewing this thread

Top Bottom