I have the following peice of code to try and send an email to selected
contacts in my form.The problem is this line:
StrStore = DLookup("[email]", "qrySelectEmail", "??????")
This looks up the email field in the records returned for the query
qrySelectEmail. The final bit needs to tell it to go to the first record
the first time the loop runs, then the second record the second time the
loop runs etc… But I cannot figure out a way to do this, which I am
certain there must be.
Thanks in anticipation
Code:
--------------------------------------------------------------------------------
Private Sub send_email_Click()On Error GoTo Err_send_email_ClickDim StrTo
As StringDim StrBcc As StringDim StrStore As StringDim NumSelected As
IntegerDim NumCurrentRecord As IntegerDim NumTotalRecords As Integer' Set
StrTo and StrBcc to emptyStrTo = ""StrBcc = ""' Check there are records
selected "NumSelected = DCount("[selected]", "qrySelectEmail", "[selected]
= TRUE")'the qryselectemail query only returns records selected and with
email adddress enteredIf NumSelected > 0 Then' Count total records
selected so that loop will stop at last recordNumTotalRecords =
DCount("[selected]", "qrySelectEmail", "[selected] = TRUE")' Set current
record to first recordNumCurrentRecord = 1' Loop through recordsDo Until
NumCurrentRecord > NumTotalRecords'The next line should needs to look up
query for each record in turnStrStore = DLookup("[email]",
"qrySelectEmail", "??????")' store email addressStrTo = StrTo + StrStore +
";"NumCurrentRecord = NumCurrentRecord + 1Loop DoCmd.SendObject
acSendNoObject, , , StrTo, , StrBcc, , , , FalseElse' There are no
selected records MsgBox ("No records have been selected")End
IfExit_send_email_Click: Exit SubErr_send_email_Click: MsgBox "The
email was not sent" Resume Exit_send_email_ClickEnd Sub
-------------------------------------------------------------------------------- 4 2774
I never use or seen example of DLookup Function used they way your
using it. But I have used it. I had to reformat copy of your code.
I'm noticing that you DLookup the store number. I think if you
selected just the store number then you could easy retrieve the email
addresses best on that particular store. If email address. changes just
change info in database through form. But use store number to pull info
you need. If that the case here then all your ducks are in order. But
that's ideal. I think ADO would be a lot faster so I am showing you
this piece of code. This doesn't answer your question. However hope
this helps.
Sub FindmeStore()
Dim mArr()
Dim mGetArr As Variant
Dim sTo As String, sBc As String, sNum As Variant
'I had nothing to test this, but this is where I would do something
similar
'known store num's in array
mArr = Array("1sd", "123")
For Each mGetArr In mArr
sNum = DLookup("[StoreNum]", "Employees", "[Selected] = True And
[StoreNum] = & mGetArr)
sBc = DLookup("[EmailManger]", "Employees", "[Selected] = True And
[StoreNum] = " & mGetArr)
sTo = DLookup("[EmployeeAddress]", "Employees", "[Selected] = True And
[StoreNum] " & mGetArr)
' DoCmd.SendObject acSendNoObject, , , sTo, , sBc, , , False
DoCmd.SendObject acSendReport, "ObjectName", , sTo, "CC", sBc,
"Store Num:" & sNum, ""
Next mGetArr
End Sub
'
'--------------------------------------------------------------------------------------------------------------------------------
Sub GetCriteria()
sql1 = "SELECT qryEmail_Addresses.Selected,
qryEmail_Addresses.EmployeeAddress ,
qryEmail_Addresses.EmailStoreMangersAddress, Email_Addresses.StoreNum"
& _
" FROM qryEmail_Addresses" & _
" Where StoreNum = """ & intStoreNum & """"
'One store at a time or if Selected = true then comment out the where
statement.
' Because of the Docmd. in the loop. I would do one store at time,
depends how many stores of course.
Set rs = New ADODB.Recordset
intStoreNum = "45D"
rs.ActiveConnection = CurrentProject.Connection
rs.LockType = adLockPessimistic
rs.CursorType = adOpenKeyset
rs.Open sql1
rs.MoveFirst
strEmpAdd = ""
strManAdd = ""
Do Until rs.EOF
If rs.Fields("Selected") = True Then
StrTo = strEmpAdd + rs.Fields("EmployeeAddress") & ";"
StrBcc = strManAdd + rs.Fields("EmailStoreMangersAddress") & ";"
'DoCmd.SendObject acSendNoObject, , , StrTo, , StrBcc, , , ,
FalseElse
'Open up immediate window see the result.
Debug.Print StrTo
Debug.Print StrBcc
End If
rs.MoveNext
Loop
' Reset Variable
StrTo = ""
StrBcc = ""
rs.Close
Set rs = Nothing
End Sub
I wrote the following to do something similar
Put the following in 'on click' event of button (called cmdEmailReps) on the
form (MyForm) you want to email from. Put a text box on this form called
'Text'.
You will need a table (MyTable) with the email addresses (E-mail) and an
index number(IndexNo) for each record. You may have a table with this info
already if so just modify field names in code below to suit your own.
The table also needs fields 'Address', 'Recipient'
You need a query (qMyTable) with all the fields from MyTable and
'[Forms]![fEmailReps]![text]' in the criteria for 'IndexNo' (no quotes)
This was quickly cobbled together from something that was specific to me to
produce code that is more general. I have not tested it so it may have some
errors. Play around with it until you get it working
Ian
************************************************** *************
Private Sub cmdEmailReps_Click()
Dim Counter As Integer
Dim stDocName As String
Dim Address As String
Dim Recipient As String
Dim Sender As String
PupFilter = "[IndexNo] = Forms!MyForm!text"
For Counter = CLng(DMin("[IndexNo]", "[qMyTable]")) To
CLng(DMax("[IndexNo]", "[qMyTable]"))
Forms!YourFormName!text = Counter
If Counter = DLookup("[IndexNo]", "[qMyTable]") Then
Recipient = DLookup("[Recipient]", "[qMyTable]", PupFilter)
Sender = "Your Name"
If IsNull(DLookup("[E-mail]", "[qMyTable]", PupFilter)) Then
MsgBox "You do not have an e-mail address for " & Recipient,
vbCritical, "Warning"
GoTo line1
Else: Address = DLookup("[E-Mail]", "[qMyTable], PupFilter")
End If
DoCmd.SendObject acReport, stDocName, acFormatRTF, Address, , ,
"Title", "Dear" & " " & Recipient & Chr(10) & Chr(10) & Chr(13) & "Type your
text here." & Chr(10) & Chr(10) & Chr(13) & "Regards" & Chr(10) & Chr(13) &
Sender, 0
MsgBox Recipient & "'s e-mail was sent successfully.", vbInformation
, "Information"
End If
line1:
Next
Exit_cmdEmailReps_Click:
Exit Sub
Err_cmdEmailReps_Click:
MsgBox Err.Description
Resume Exit_cmdEmailReps_Click
End Sub
************************************************** ******
"acni" <nb***@artscouncil-ni.org> wrote in message
news:f2******************************@localhost.ta lkaboutdatabases.com... I have the following peice of code to try and send an email to selected contacts in my form.The problem is this line:
StrStore = DLookup("[email]", "qrySelectEmail", "??????")
This looks up the email field in the records returned for the query qrySelectEmail. The final bit needs to tell it to go to the first record the first time the loop runs, then the second record the second time the loop runs etc. But I cannot figure out a way to do this, which I am certain there must be.
Thanks in anticipation
Code: --------------------------------------------------------------------------
------ Private Sub send_email_Click()On Error GoTo Err_send_email_ClickDim StrTo As StringDim StrBcc As StringDim StrStore As StringDim NumSelected As IntegerDim NumCurrentRecord As IntegerDim NumTotalRecords As Integer' Set StrTo and StrBcc to emptyStrTo = ""StrBcc = ""' Check there are records selected "NumSelected = DCount("[selected]", "qrySelectEmail", "[selected] = TRUE")'the qryselectemail query only returns records selected and with email adddress enteredIf NumSelected > 0 Then' Count total records selected so that loop will stop at last recordNumTotalRecords = DCount("[selected]", "qrySelectEmail", "[selected] = TRUE")' Set current record to first recordNumCurrentRecord = 1' Loop through recordsDo Until NumCurrentRecord > NumTotalRecords'The next line should needs to look up query for each record in turnStrStore = DLookup("[email]", "qrySelectEmail", "??????")' store email addressStrTo = StrTo + StrStore + ";"NumCurrentRecord = NumCurrentRecord + 1Loop DoCmd.SendObject acSendNoObject, , , StrTo, , StrBcc, , , , FalseElse' There are no selected records MsgBox ("No records have been selected")End IfExit_send_email_Click: Exit SubErr_send_email_Click: MsgBox "The email was not sent" Resume Exit_send_email_ClickEnd Sub --------------------------------------------------------------------------
------
Typo '[Forms]![fEmailReps]![text]' in the criteria for 'IndexNo' (no quotes)
should be
'[Forms]![MyForm]![text]' in the criteria for 'IndexNo' (no quotes)
or what ever you decided to call your form
Also to make it more selective you can put dropdown lists on the form to
enable u to choose criteria. These criteria can then be fed into the query
Ian
"Ian Davies" <ia********@virgin.net> wrote in message
news:Tv***************@newsfe2-win.ntli.net... I wrote the following to do something similar
Put the following in 'on click' event of button (called cmdEmailReps) on
the form (MyForm) you want to email from. Put a text box on this form called 'Text'.
You will need a table (MyTable) with the email addresses (E-mail) and an index number(IndexNo) for each record. You may have a table with this
info already if so just modify field names in code below to suit your own.
The table also needs fields 'Address', 'Recipient'
You need a query (qMyTable) with all the fields from MyTable and '[Forms]![fEmailReps]![text]' in the criteria for 'IndexNo' (no quotes)
This was quickly cobbled together from something that was specific to me
to produce code that is more general. I have not tested it so it may have
some errors. Play around with it until you get it working
Ian
************************************************** ************* Private Sub cmdEmailReps_Click()
Dim Counter As Integer Dim stDocName As String Dim Address As String Dim Recipient As String Dim Sender As String
PupFilter = "[IndexNo] = Forms!MyForm!text"
For Counter = CLng(DMin("[IndexNo]", "[qMyTable]")) To CLng(DMax("[IndexNo]", "[qMyTable]"))
Forms!YourFormName!text = Counter
If Counter = DLookup("[IndexNo]", "[qMyTable]") Then
Recipient = DLookup("[Recipient]", "[qMyTable]", PupFilter) Sender = "Your Name"
If IsNull(DLookup("[E-mail]", "[qMyTable]", PupFilter)) Then MsgBox "You do not have an e-mail address for " & Recipient, vbCritical, "Warning" GoTo line1 Else: Address = DLookup("[E-Mail]", "[qMyTable], PupFilter") End If
DoCmd.SendObject acReport, stDocName, acFormatRTF, Address, , , "Title", "Dear" & " " & Recipient & Chr(10) & Chr(10) & Chr(13) & "Type
your text here." & Chr(10) & Chr(10) & Chr(13) & "Regards" & Chr(10) & Chr(13)
& Sender, 0 MsgBox Recipient & "'s e-mail was sent successfully.",
vbInformation , "Information" End If
line1: Next
Exit_cmdEmailReps_Click: Exit Sub
Err_cmdEmailReps_Click: MsgBox Err.Description Resume Exit_cmdEmailReps_Click
End Sub
************************************************** ******
"acni" <nb***@artscouncil-ni.org> wrote in message news:f2******************************@localhost.ta lkaboutdatabases.com... I have the following peice of code to try and send an email to selected contacts in my form.The problem is this line:
StrStore = DLookup("[email]", "qrySelectEmail", "??????")
This looks up the email field in the records returned for the query qrySelectEmail. The final bit needs to tell it to go to the first record the first time the loop runs, then the second record the second time the loop runs etc. But I cannot figure out a way to do this, which I am certain there must be.
Thanks in anticipation
Code:
-------------------------------------------------------------------------- ------ Private Sub send_email_Click()On Error GoTo Err_send_email_ClickDim
StrTo As StringDim StrBcc As StringDim StrStore As StringDim NumSelected As IntegerDim NumCurrentRecord As IntegerDim NumTotalRecords As Integer'
Set StrTo and StrBcc to emptyStrTo = ""StrBcc = ""' Check there are records selected "NumSelected = DCount("[selected]", "qrySelectEmail",
"[selected] = TRUE")'the qryselectemail query only returns records selected and with email adddress enteredIf NumSelected > 0 Then' Count total records selected so that loop will stop at last recordNumTotalRecords = DCount("[selected]", "qrySelectEmail", "[selected] = TRUE")' Set current record to first recordNumCurrentRecord = 1' Loop through recordsDo Until NumCurrentRecord > NumTotalRecords'The next line should needs to look up query for each record in turnStrStore = DLookup("[email]", "qrySelectEmail", "??????")' store email addressStrTo = StrTo + StrStore
+ ";"NumCurrentRecord = NumCurrentRecord + 1Loop DoCmd.SendObject acSendNoObject, , , StrTo, , StrBcc, , , , FalseElse' There are no selected records MsgBox ("No records have been selected")End IfExit_send_email_Click: Exit SubErr_send_email_Click: MsgBox "The email was not sent" Resume Exit_send_email_ClickEnd Sub
-------------------------------------------------------------------------- ------
acni wrote: I have the following peice of code to try and send an email to selected contacts in my form.The problem is this line:
StrStore = DLookup("[email]", "qrySelectEmail", "??????")
This looks up the email field in the records returned for the query qrySelectEmail. The final bit needs to tell it to go to the first record the first time the loop runs, then the second record the second time the loop runs etc… But I cannot figure out a way to do this, which I am certain there must be.
Thanks in anticipation
This approach may be a little different but it works well for me and
it's easy to maintain.
I have a table of "Groups" which contains logical group names I want to
email. Then I have a table of "Recipients" that has a foreign key to
Groups, actual email addresses, and a boolean "active" value. On my form
I have a few command buttons corresponding to the groups. You may
consider populating a combobox or listbox with the group names instead
of individual command buttons, especially if you have several groups or
the group population tends to change.
The buttons fire code which runs SQL to obtain the active email addys
for the group, builds the recipient list, subject and message, and does
the DoCmd that actually creates the email.
HTH
--
Smartin This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Ann |
last post by:
Hi,
I am trying to send a html email from a php script. This script emails
a common information to all the members in the database. The only
problem is I cannot specify colors, hyperlinks...
|
by: acni |
last post by:
hey
just wondering if anyone could offer a bit of advice to me.i have a
database with a list of contacts on it with a checkbox beside each one.i
was wondering if it was possible to place a...
|
by: Kenneth H. Young |
last post by:
I have written an LDAP application that allows user to select contacts from
the search result data-grid and then click on an email to button which
generates a new email and populates the To: field...
|
by: daniel.czestki |
last post by:
Hello,
In my MS Outlook I use global address book to handling contacts.
When I send email from Outlook to myself and double click on sender I
get information about me from my global address...
|
by: Tomdhu |
last post by:
I've got a Contacts & Events database in Access 2K where contacts
attend various events.
At present, where I want to group e-mail all the attendees who are
going to attend a particular event, I...
|
by: Eric Sheu |
last post by:
Greetings,
I have been searching the web like mad for a solution to my SMTP problem. I
am using Windows Server 2003 and ASP.NET 2.0 w/ C# to send out e-mails from a
web site I have created to...
|
by: tara99 |
last post by:
How can I send email to many contacts at the same time by a click of a button?
|
by: =?Utf-8?B?U3Jpbml2YXNhIE5hZGVsbGE=?= |
last post by:
Hi
Can any one please help me out in getting the source code of Importing the
Email Contact Lists from Yahoo or MSN or any email subscriber.
This is very urgent for me. I tried in the Internet...
|
by: PrabodhanP |
last post by:
I have form on my website.I am sending data entered by visitor to particular email-id through php script.Now I want to add some radio buttons and depending on selacted radio button form data should...
|
by: DolphinDB |
last post by:
Tired of spending countless mintues downsampling your data? Look no further!
In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
|
by: ryjfgjl |
last post by:
ExcelToDatabase: batch import excel into database automatically...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: Vimpel783 |
last post by:
Hello!
Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
|
by: jfyes |
last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
|
by: ArrayDB |
last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
|
by: CloudSolutions |
last post by:
Introduction:
For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
|
by: Defcon1945 |
last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
|
by: Shællîpôpï 09 |
last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
| |