While Not rs.EOF Status "Email Address: " & rs!Email
'This is the code for sending through Outlook SendOutlookEmail rs!Email, Nz(CC), Nz(BCC), Subject, Body, Nz(Attachment, ""), Nz(ReplyTo, "")
'This is the code for sending through gmail 'SendEmail rs!Email, "[email protected]", Nz(Subject), Nz(Body), "[email protected]", Nz(CC), Nz(BCC), True, Nz(Attachment, "")
rs.MoveNext
SleepSec 10 Wend rs.Close
Set rs = Nothing Status "Email Sent"
End Sub
Tom MuraOP
@Reply 9 months ago
This does produce a message box that includes the code: SELECT * FROM TeamT WHERE GradeGender = """ & Forms!EmailBulkF!GradeGenderFIlterTxt & """ AND Email IS NOT NULL AND Email <> """"
But it doesn't run.
Tom MuraOP
@Reply 9 months ago
One more piece of the puzzle: When I 'Hard Code' the SQL into the record set everything works fine. The issue seems to be with using the text box to hold the sql but I can't figure out why.
Adam Schwanz
@Reply 9 months ago
Why don't you just program that into the Actual code instead of a textbox?
Also where is this code from? I just went and downloaded the new email seminar to try and look for the SendOutlookEmail function, but I don't see it.
Also, what do you mean by "doesnt run". Does it error or anything? Have you tried adding a Msgbox "Test" to the end of the code after everything is done to see if it reaches that point?
Can you put the SQL to a variable then print or MsgBox the output
Adam Schwanz
@Reply 9 months ago
You replied while I was typing that out lol.
I know it's possible but I don't remember how off the top of my head to use a "string" as actual code. You should just hard code it
Tom MuraOP
@Reply 9 months ago
Thank you for help Alex and Adam!
The SendOutlookEmail function comes from Email Seminar. I may have tweaked the name but that is the code it is running.
When I say 'It doesn't run. " I mean that it doesn't put the email address in the status box and it doesn't send an email.
I can hard code it into a button but means I have to change it each time I want to run the new SQL statement. I was hoping for a more flexible solution.
One time I may need to send an email to the families of players who have not provided a birth certificate for their child. Another time I'd like send an email to all of our coaches who have not completed their background check. Being able to store those Sql statements in a table and select them from a combo box would be much quicker than changing the Sql in the recordset each time.
Thanks Alex. I've watched the Search Form 2.0 video and my searches are working properly. I added some error handling (thanks ChatGPT Canvas!) and the recordset is not producing any records.
When I use this sql: ("SELECT * FROM TeamT WHERE GradeGender = """ & Forms!EmailBulkF!GradeGenderFIlterTxt & """ AND Email IS NOT NULL AND Email <> """"") in the VBA code it works correctly. If I plug this same code into a text box and reference it in the recordset as SqlCodeText. It gives me an error saying that it can't find a table or query with that name. If I removed the leading and trailing ( and ". It runs but doesn't generate any records.
I really appreciate your help hope that this additional info can help you point me in the right direction.
When I plug this sql into the vba code I get:("SELECT * FROM TeamT WHERE GradeGender = """ & Forms!EmailBulkF!GradeGenderFIlterTxt & """ AND Email IS NOT NULL AND Email <> """""). When I put it into the text field and refer to it I get nothing in the immediate window because it shows and no records. Is there some difference in the code between what goes straight into VBA and what will come from a text box?
Kevin Robertson
@Reply 9 months ago
instead of Email IS NOT NULL try Not IsNull(Email).
I want to see what your SQL String converts to, for example
SELECT * FROM TeamT WHERE GradeGender = "abc" AND Email IS NOT NULL AND Email <> ""
Tom MuraOP
@Reply 9 months ago
When I tried: ("SELECT * FROM TeamT WHERE GradeGender = """ & Forms!EmailBulkF!GradeGenderFIlterTxt & """ AND Email IS NOT NULL AND Email <> """"") 'I got "Invalid use of Null'
Tom MuraOP
@Reply 9 months ago
In my previous post when I said, "When I plug this sql into the vba code I get:("SELECT * FROM TeamT WHERE GradeGender = """ & Forms!EmailBulkF!GradeGenderFIlterTxt & """ AND Email IS NOT NULL AND Email <> """"")." I should have added that it works fine. Sorry any confusion that this caused.
Forms!EmailBulkF!GradeGenderFIlterTxt should be converting to whatever your text is that you typed in, if it's treating that as literal text it won't work.
Tom MuraOP
@Reply 9 months ago
I just tried to enter, SELECT PlayerT. * FROM PlayerT - as the most basic sql statement.
I got this, "An error occurred: Syntax error (missing operator) in query expression 'PlayerT*.
Thanks Alex. Then what should it be converting to if not text?
You have Set rs = CurrentDb.OpenRecordset(SqlCodeText) What does SqlCodeText print out?
Or you could MsgBox it.
Tom MuraOP
@Reply 9 months ago
I already have Set rs = CurrrentDb.OpenRecordset (SqlCodeText) in my code. Debug.Print SqlCodeText shows the code I have entered in the Forms!EmailBulkF!GradeGenderFIlterTxt field.
Tom MuraOP
@Reply 9 months ago
But that's only if the code runs. I just put this into the sql query editor and it worked fine: SELECT * FROM TeamT WHERE (((TeamT.GradeGender)=[Forms]![EmailBulkF]![GradeGenderFilterTxt]) AND ((TeamT.Email) Is Not Null))
It will not work from the text box referenced in the vba code.
Tom MuraOP
@Reply 9 months ago
The message I'm getting when referring to this code from a text box in a form is: 'An error occurred: Too few parameters. Expected 1. It works find when I copy and paste the same code directly into the VBA. Is that helpful in diagnosing the issue?
Tom MuraOP
@Reply 9 months ago
I narrowed down the problem to using a combo box on the email form as the problem. When I used Sql without a combo box it all worked perfectly. Thanks for all you did to try to help.
Sorry, only students may add comments.
Click here for more
information on how you can set up an account.
If you are a Visitor, go ahead and post your reply as a
new comment, and we'll move it here for you
once it's approved. Be sure to use the same name and email address.
This thread is now CLOSED. If you wish to comment, start a NEW discussion in
Email Seminar Lessons.
The following is a paid advertisement
Computer Learning Zone is not responsible for any content shown or offers made by these ads.