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_Clic k()On Error GoTo Err_send_email_ ClickDim StrTo
As StringDim StrBcc As StringDim StrStore As StringDim NumSelected As
IntegerDim NumCurrentRecor d As IntegerDim NumTotalRecords As Integer' Set
StrTo and StrBcc to emptyStrTo = ""StrBcc = ""' Check there are records
selected "NumSelecte d = 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 recordNumTotalR ecords =
DCount("[selected]", "qrySelectEmail ", "[selected] = TRUE")' Set current
record to first recordNumCurren tRecord = 1' Loop through recordsDo Until
NumCurrentRecor d > NumTotalRecords 'The next line should needs to look up
query for each record in turnStrStore = DLookup("[email]",
"qrySelectEmail ", "??????")' store email addressStrTo = StrTo + StrStore +
";"NumCurrentRe cord = NumCurrentRecor d + 1Loop DoCmd.SendObjec t
acSendNoObject, , , StrTo, , StrBcc, , , , FalseElse' There are no
selected records MsgBox ("No records have been selected")End
IfExit_send_ema il_Click: Exit SubErr_send_ema il_Click: MsgBox "The
email was not sent" Resume Exit_send_email _ClickEnd Sub
-------------------------------------------------------------------------------- 4 2791
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.SendObjec t acSendNoObject, , , sTo, , sBc, , , False
DoCmd.SendObjec t acSendReport, "ObjectName ", , sTo, "CC", sBc,
"Store Num:" & sNum, ""
Next mGetArr
End Sub
'
'--------------------------------------------------------------------------------------------------------------------------------
Sub GetCriteria()
sql1 = "SELECT qryEmail_Addres ses.Selected,
qryEmail_Addres ses.EmployeeAdd ress ,
qryEmail_Addres ses.EmailStoreM angersAddress, Email_Addresses .StoreNum"
& _
" FROM qryEmail_Addres ses" & _
" 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.ActiveConnec tion = CurrentProject. Connection
rs.LockType = adLockPessimist ic
rs.CursorType = adOpenKeyset
rs.Open sql1
rs.MoveFirst
strEmpAdd = ""
strManAdd = ""
Do Until rs.EOF
If rs.Fields("Sele cted") = True Then
StrTo = strEmpAdd + rs.Fields("Empl oyeeAddress") & ";"
StrBcc = strManAdd + rs.Fields("Emai lStoreMangersAd dress") & ";"
'DoCmd.SendObje ct 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_Cl ick()
Dim Counter As Integer
Dim stDocName As String
Dim Address As String
Dim Recipient As String
Dim Sender As String
PupFilter = "[IndexNo] = Forms!MyForm!te xt"
For Counter = CLng(DMin("[IndexNo]", "[qMyTable]")) To
CLng(DMax("[IndexNo]", "[qMyTable]"))
Forms!YourFormN ame!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.SendObjec t 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
, "Informatio n"
End If
line1:
Next
Exit_cmdEmailRe ps_Click:
Exit Sub
Err_cmdEmailRep s_Click:
MsgBox Err.Description
Resume Exit_cmdEmailRe ps_Click
End Sub
*************** *************** *************** ***********
"acni" <nb***@artscoun cil-ni.org> wrote in message
news:f2******** *************** *******@localho st.talkaboutdat abases.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_Clic k()On Error GoTo Err_send_email_ ClickDim StrTo As StringDim StrBcc As StringDim StrStore As StringDim NumSelected As IntegerDim NumCurrentRecor d As IntegerDim NumTotalRecords As Integer' Set StrTo and StrBcc to emptyStrTo = ""StrBcc = ""' Check there are records selected "NumSelecte d = 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 recordNumTotalR ecords = DCount("[selected]", "qrySelectEmail ", "[selected] = TRUE")' Set current record to first recordNumCurren tRecord = 1' Loop through recordsDo Until NumCurrentRecor d > NumTotalRecords 'The next line should needs to look up query for each record in turnStrStore = DLookup("[email]", "qrySelectEmail ", "??????")' store email addressStrTo = StrTo + StrStore + ";"NumCurrentRe cord = NumCurrentRecor d + 1Loop DoCmd.SendObjec t acSendNoObject, , , StrTo, , StrBcc, , , , FalseElse' There are no selected records MsgBox ("No records have been selected")End IfExit_send_ema il_Click: Exit SubErr_send_ema il_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********@vir gin.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_Cl ick()
Dim Counter As Integer Dim stDocName As String Dim Address As String Dim Recipient As String Dim Sender As String
PupFilter = "[IndexNo] = Forms!MyForm!te xt"
For Counter = CLng(DMin("[IndexNo]", "[qMyTable]")) To CLng(DMax("[IndexNo]", "[qMyTable]"))
Forms!YourFormN ame!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.SendObjec t 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 , "Informatio n" End If
line1: Next
Exit_cmdEmailRe ps_Click: Exit Sub
Err_cmdEmailRep s_Click: MsgBox Err.Description Resume Exit_cmdEmailRe ps_Click
End Sub
*************** *************** *************** ***********
"acni" <nb***@artscoun cil-ni.org> wrote in message news:f2******** *************** *******@localho st.talkaboutdat abases.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_Clic k()On Error GoTo Err_send_email_ ClickDim
StrTo As StringDim StrBcc As StringDim StrStore As StringDim NumSelected As IntegerDim NumCurrentRecor d As IntegerDim NumTotalRecords As Integer'
Set StrTo and StrBcc to emptyStrTo = ""StrBcc = ""' Check there are records selected "NumSelecte d = 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 recordNumTotalR ecords = DCount("[selected]", "qrySelectEmail ", "[selected] = TRUE")' Set current record to first recordNumCurren tRecord = 1' Loop through recordsDo Until NumCurrentRecor d > NumTotalRecords 'The next line should needs to look up query for each record in turnStrStore = DLookup("[email]", "qrySelectEmail ", "??????")' store email addressStrTo = StrTo + StrStore
+ ";"NumCurrentRe cord = NumCurrentRecor d + 1Loop DoCmd.SendObjec t acSendNoObject, , , StrTo, , StrBcc, , , , FalseElse' There are no selected records MsgBox ("No records have been selected")End IfExit_send_ema il_Click: Exit SubErr_send_ema il_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 etc..Html tags like
<h1></h1>, <br/>, <b> etc works though..
Could any one tell me what i might be doing wrong? Any help will be
greatly appreciated.
|
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 command button on the form so
that when you click it it opens an email to send to all those with the
ticked check box?
Thanks in anticipation
|
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 with the selected
contacts. Note: The application reads the registry to determine what the
default email client is and then executes the appropriate...
|
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 book.
When I use php mail() function to sending messages and then double
click on sender I get specificity message email window only.
How do I have...
|
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 run a macro which runs a select
query which strips out and exports a list of their e-mail addresses (
separated by commas) into a text file. 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 the members of my organization. I think my problem
is incorrectly setting the settings on my server or an authentication
problem. Here is the code I...
|
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 but I could not get any
proper solution for this. I saw lot of web sites and almost all the apps
which they provide are shareware. No freeware app...
|
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 go to different email-id.
For example , I have radio buttons,like abc,xyz and pqr....if abc selected form data will go abc@yahoo.com and xyz is...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it. ...
| |
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in...
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...
| |