Education is the most powerful weapon
which you can use to change the world.
-Nelson Mandela
 
Home   News   Tips   Glossary   Templates   Forums   Help   Logon   Order   Contact Us  
 

Forums     

Visual Basic Forum
By Richard Rost   Richard Rost on Facebook Richard Rost on Twitter Richard Rost on Google Plus Richard Rost on LinkedIn Email Richard Rost

 
This forum is for the discussion of Visual Basic programming and development.

Click Here To Subscribe to this forum and receive an email update whenever new posts are added, just scroll down to the bottom of this page and enter your email address in the comment form.

Permanent Link
Keywords: vb forum visual basic
Post New Topic

Read VBA Code Query and Form Control to send Email by Shepherd C @ 12/1/2014
Dear Richard Rost,

I am disparate I need your help Richard! I have a workflow written in VBA code to send emails with details about employees who are on probation.  Ideally we would like this workflow to send emails to the HR Coordinator by simply opening the relevant employee s form and clicking on the  Send Email  button. The email should pick up the Manager s name from the rst.Fields( Mgr s Name ) as set up in the code below. The problem I am facing is that if I put reference to some Form control in the Design View of the Query it does not work. I am getting the error message:  Run-time error  3061  Too few parameters. Expected 1 . However, if I but if I put reference to the value in the Query s Design View i.e. the employee number it works. The HR Co-odinator is not that technical and she does not want to go through the trouble of going to the Design View to populate a employee number each time she wants to send an email.

How to I correct the VBA code to work. Below is the VBA code.

Thanks

Shep

Private Sub Command84_Click()
Dim dbs As DAO.Database
Dim rst As DAO.Recordset
Dim strTo As String
Dim strSubject As String
Dim strMessage As String
Set dbs = CurrentDb
Set rst = dbs.OpenRecordset("Probation Details_emailing", dbOpenForwardOnly)
Do While Not rst.EOF
strTo = rst.Fields("HR Coordinator Email")
strSubject = "Probation Report" 'could be made available
strSubject = "Probation Report" 'could be made available
strMessage = "Dear " & rst.Fields("Mgr's Name") & vbNewLine & vbNewLine & _
"Employee name probation period ends on date.  Are you happy for me to issue a congratulatory letter?" & vbNewLine & vbNewLine & "FYI - I shall send the letter out on your behalf and it will have the following wording.If you would like to amend or add any comments please include them in your reply.  I will also arrange for a copy to be placed onto the employee's personnel file." & vbNewLine & vbNewLine & _
"I am pleased to confirm that you have successfully completed your probation period with PickSP Consulting Ltd on (date will be entered by HR) and I would like to take this opportunity to wish you every success in your future employment with us." & vbNewLine & vbNewLine & vbNewLine & vbNewLine & "Many Thanks for your time." & vbNewLine & vbNewLine & vbNewLine & vbNewLine & "Joseph Jones" & vbNewLine & "HR Co-ordinator" & vbNewLine & vbNewLine & "222222/ 7777777777" & vbNewLine & "Email: joseph.jones@hotmail.com"

DoCmd.SendObject acQuery, "Probation Details_emailing", "ExcelWorkbook(*.xlsx)", strTo, "", "", "Probation Report", strMessage, False, ""
  
  rst.MoveNext
  Loop
'close the objects
  rst.Close
  dbs.Close
  
'destroy the variables
  Set rst = Nothing
  Set dbs = Nothing

End Sub


Reply from Alex Hedley:

Hi Shep,

Firstly try not to have spaces in your FIELD and QUERY names, it can cause issues when used in code.

I'd change the FIELD from ("Mgr's Name") to ("MgrsName") in the TABLE.

Does the QUERY "Probation Details_emailing" contain these Fields you are trying to access in your Recordset?
Show Just This Thread        Post Reply

Collapse All Topics

 

Post Your Comments or Subscribe
    If you would like to be notified of new posts on this forum,
    just enter your email address below. It will be kept private.
 
If you just want to subscribe to get email updates when this forum is updated, then enter your name and email address and check the Notify Me box below. If you would optionally like to add your comments below to be posted, they are welcome.
 
  Your Name:  Required
  Your Email:  NOT Public
  Subject:
  Comments:

 

Sorry about this step. It's just to keep the spam bots away:
  Verify: What is 8+7:
  
  Notify me when the this forum is updated
  Remember Me for my next comments
  
 
 
Please do not use this form for Customer Service inquiries! If you have questions about your account, shipping info, courses you've ordered, need passwords, etc. please use the Customer Service Center instead.

I value your comments. They will be displayed on this page (above). Your name will be displayed, but your email address will not be.
As always, I promise to never give away your personal information to anyone else, ever.

NOTE: If you don't leave your name and email address, DON'T expect a reply. I can't promise a personal reply to everyone who posts here. I TRY my best, but I cannot guarantee it. If you don't leave your real name and email address, I won't even bother. I usually just hit DELETE. -Richard

 

 
 

Learn
 
Accessindex
Excelindex
Wordindex
Windowsindex
PowerPointindex
Photoshopindex
Visual Basicindex
ASPindex
Seminars
More...
Customers
 
Account Login
Online Theater
Downloads
Lost Password
Free Upgrades
Insider Circle
Student Databases
Change Email
Info
 
Latest News
New Releases
User Forums
Topic Glossary
Tips & Tricks
Articles
Search Our Site
Waiting List
Production Schedule
Collapse Menus
Help
 
Live Chat
Customer Support
WalkThru Tutorials
Troubleshooting
FAQs
TechHelp
Consulting Services
About Us
 
Background
Testimonials
Jobs
Affiliate Program
Richard Rost
Free Lessons
Mailing List
Order
 
Video Tutorials
Handbooks
MYOLP Memberships
Idiot's Guide to Excel
Volume Discounts
Payment Info
Shipping
Terms of Sale
Gift CDs
Contact
 
Live Chat
General Info
Support Policy
Contact Form
Email Us
Mailing Address
Phone Number
Fax Number
Course Survey
Facebook    Twitter

Google Plus    LinkedIn

Blog RSS Feed    YouTube Channel
Richard Rost Microsoft MVP