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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Need help with email VBA 1

Status
Not open for further replies.

platypus71

Technical User
Sep 7, 2005
68
US
I have a Function SendEmail(strTo, strMessage, strAttach, strSubject, strBCC) defined and works just fine.

I have previously created functions that ran against the SendEmail function and they have worked just fine. I have since written the following Function and am getting an error and don't understand why.

Code:
Function PostTests()
    Dim X As Boolean
    Dim mydb As Database
    Dim rst As Recordset
    Dim sqlstr As String
    Dim writelog As String
    Dim sbj As String
    Dim bod As String
    Dim MailType As String
    TestType = "Post"
    sqlstr = "SELECT tblTestURL.URL, tblPerfManageTest.Name, tblPerfManageTest.NotesID, tblPerfManageTest.TestName, tblPerfManageTest.TestType, tblPerfManageTest.ClassDate, tblPostTestsLog.TestType FROM tblPerfManageTest LEFT JOIN tblPostTestsLog ON (tblPerfManageTest.NotesID = tblPostTestsLog.NotesID) AND (tblPerfManageTest.TestName = tblPostTestsLog.TestName)WHERE (((tblPerfManageTest.TestType) Like 'Pre') AND ((tblPostTestsLog.TestType) Is Null));"
    
    Set mydb = CurrentDb
    Set rst = mydb.OpenRecordset(sqlstr)
    Do While Not rst.EOF
    sbj = "Post Test for " & rst!TestName & ""
    bod = "Dear " & rst!Name & vbCrLf & "Please take a few minutes to complete our Post test for the " & rst!TestName & " class you recently attended.  You can get to the online test by going to " & rst!URL & "." & vbCrLf & vbCrLf & "Thank you!" & vbCrLf & "Luigi"
    
    X = SendEmail(rst!NotesID, bod, "", sbj, "")
    writelog = "INSERT INTO tblPostTestsLog( NotesID, TestType, TestName ) IN 'J:\Databases\Training.mdb' VALUES('" & rst!UserID & "','" & TestType & "', '" & rst!TestName & "')"
    
    DoCmd.RunSQL writelog
    rst.MoveNext
    Loop

End Function

The error I get is Run-time error '3061': Too few parameters. Expected 1.

The only lines that have changed from previous functions are the lines that start with sqlstr, sbj, bod, and writelog.

Any help would be appreciated.
 
I've been out of the loop regarding recordsets for quite a while, but first things first.

Does your query (sqlstr) run if you paste it into a new query window?

[small]----signature below----[/small]
Majority rule don't work in mental institutions

My Crummy Web Page
 
I'm an idiot. I learned previously with recordsets to create my query in the query builder to make sure it worked, then paste it into the VB Editor.

Unfortunately, after I did this, I modified it and never checked that it still worked. Thanks for the reminder. I fixed the query in the query builder and all is good now.

Note if anyone reads this post for reference. In the query builder, where double quotes (") work, you have to change them to single quotes (') in the VB code.
 
In the query builder, where double quotes (") work, you have to change them to single quotes (') in the VB code
Doesn't single quotes work in the query builder ?

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Every time I use single quotes in the query builder, save/exit my query, then open it back up, it always converts them back to double quotes.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top