Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsFormsForms ProgrammingQueriesModules / DAO / VBAReports / PrintingMacrosDatabase DesignSecurityConversionImporting / LinkingSQL Server / ADPMultiuser / NetworkingReplicationSetup / ConfigurationDeveloper ToolkitsActiveX ControlsNew UsersGeneral 1General 2
Access DirectoryToolsTutorialsUser Groups
Related Topics
SQL ServerOther DB ProductsMS OfficeMore Topics ...

MS Access Forum / Forms Programming / September 2007

Tip: Looking for answers? Try searching our database.

sql limited by parameter

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Stephanie - 29 Sep 2007 18:23 GMT
Hi. I am able to loop through my records and create an email, EXCEPT I'm not
limiting my email addresses based on one of the parameters.

I have Contacts that hold Licenses. I want to send an email to all Contacts
(that are in good standing) and have a current license as stated in the input
parameter- this is the part that is not working.

The set up: Contacts hold contact info, Licenses hold license info,
LicenseMembers is the many-to-one linking table.

I have a LiceseQuery that works:
SELECT Contacts.ContactID, Contacts.EmailName1, nz([NickName],[FirstName]) &
" " & [LastName] AS [Member Name], Licenses.LicenseName,
licenseMembers.LicenseID, licenseMembers.LicenseStart,
licenseMembers.LicenseEnd, Contacts.StateOrProvince1,
MemberStatus.MemberStatusID
FROM (Licenses INNER JOIN (Contacts INNER JOIN licenseMembers ON
Contacts.ContactID = licenseMembers.ContactID) ON Licenses.LicenseID =
licenseMembers.LicenseID) INNER JOIN MemberStatus ON Contacts.MemberStatusID
= MemberStatus.MemberStatusID
WHERE (((Licenses.LicenseName)=[forms]![LicenseParam]![FindLicense]) AND
((licenseMembers.LicenseEnd)>Now() Or (licenseMembers.LicenseEnd) Is Null)
AND ((MemberStatus.MemberStatusID) In (1,6)));

This query limits the licenses just right.

I thought I could just convert this sql to sql that VBA would understand,
but I can't get it quite right.

I started with a smaller query to simplify things, because all I need in
"Contacts" is the email address (and because I could get str sql to work
using the LicenseQuery)-
ContactView query:
SELECT Contacts.ContactID, Contacts.EmailName1, Contacts.MemberStatusID,
FROM Contacts
WHERE (((Contacts.EmailName1) Is Not Null) AND ((Contacts.MemberStatusID) In
(1,6)));

Here's my str sql:
   sql = "SELECT ContactView.EmailName1 FROM LicenseMembers INNER JOIN " +
"ContactView ON LicenseMembers.ContactID = ContactView.ContactID " + "WHERE
(((LicenseMembers.LicenseID)=" + CStr(Me.FindLicense) + ") AND
((LicenseMembers.LicenseEnd) Is Null) OR (LicenseMembers.LicenseEnd)>Now());"

I'm prompted to chose the license parameter, and then the code ignores the
parameter and creates an email. I can't quite figure out how it is
determining who to include on the email list or what I've done wrong. I have
similar email generation VBA statements and they work fine. Little comfort!
I'd appreciate your suggestions. Thanks.
tina - 29 Sep 2007 22:46 GMT
try

   sql = "SELECT ContactView.EmailName1 " _
       & "FROM LicenseMembers INNER JOIN " _
       & "ContactView ON " _
       & "LicenseMembers.ContactID = " _
       & "ContactView.ContactID WHERE " _
       & "LicenseMembers.LicenseID = " _
       & CStr(Me!FindLicense) & " AND (" _
       & "LicenseMembers.LicenseEnd Is Null OR " _
       & "LicenseMembers.LicenseEnd > #" & Date & "#)"

note that i used Date instead of Now, because Now returns the current date
AND time (hour, minute, second), while Date returns only the current date.

hth

> Hi. I am able to loop through my records and create an email, EXCEPT I'm not
> limiting my email addresses based on one of the parameters.
[quoted text clipped - 45 lines]
> similar email generation VBA statements and they work fine. Little comfort!
> I'd appreciate your suggestions. Thanks.
Stephanie - 30 Sep 2007 00:35 GMT
Tina, You Rock!
Thanks for taking the time to run through a messy posting and for the
reminder of an easier method for listing sql and for the "date" vs. "now"
lesson. I actually had my parameter form backward (id vs. name) but couldn't
see that until you helped with the code. I appreciate your help!

> try
>
[quoted text clipped - 73 lines]
> comfort!
> > I'd appreciate your suggestions. Thanks.
tina - 30 Sep 2007 05:47 GMT
> Tina, You Rock!

...n' Roll - but that's dating me a bit, i know!  ;)
and you're welcome  :)

> Tina, You Rock!
> Thanks for taking the time to run through a messy posting and for the
[quoted text clipped - 58 lines]
> > > ContactView query:
> > > SELECT Contacts.ContactID, Contacts.EmailName1,
Contacts.MemberStatusID,
> > > FROM Contacts
> > > WHERE (((Contacts.EmailName1) Is Not Null) AND ((Contacts.MemberStatusID)
[quoted text clipped - 17 lines]
> > comfort!
> > > I'd appreciate your suggestions. Thanks.
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.