query to overcome field type problem?

I have a contacts table... let's say 2 fields- ID and email.
I have a groups table... it has a number of fields that are linked back to 
the contacts field already (contact 1 thru nn), so that the groups table just 
has a contact id number and I look up their email from the other table.  One 
field is also the "primary contact" (similarly linked)... for the person who 
"owns" that group.

Works nicely so far, (thanks, techrat!).  Until I try to send email to that 
primary contact to have them verify the details.... Their email id doesn't 
show up in the wizard, since it's just a number.  

So I'm trying to write a query to also select the email address and return 
it in my results... without any luck so far.  I'm getting sql syntax errors.  
Here's the kind of query I'm attempting:

SELECT GroupName, Primary, 
 (select Contacts.[E-mail Address] where Contacts.ID = Primary)
FROM Groups;

suggestions for a newbie?  thanks
0
Utf
12/13/2009 12:31:02 AM
access.queries 6343 articles. 1 followers. Follow

4 Replies
704 Views

Similar Articles

[PageSpeed] 45

I believe you should be using a join rather than a subquery.

SELECT GroupName, Primary, [E-mail Address]
FROM Groups JOIN Contacts on Contacts.ID = Groups.Primary;

Also, if you multiple contact fields in the Groups table, yhou might want to 
consider normalizing your table structures.

-- 
Duane Hookom
Microsoft Access MVP


"Slushpump" wrote:

> I have a contacts table... let's say 2 fields- ID and email.
> I have a groups table... it has a number of fields that are linked back to 
> the contacts field already (contact 1 thru nn), so that the groups table just 
> has a contact id number and I look up their email from the other table.  One 
> field is also the "primary contact" (similarly linked)... for the person who 
> "owns" that group.
> 
> Works nicely so far, (thanks, techrat!).  Until I try to send email to that 
> primary contact to have them verify the details.... Their email id doesn't 
> show up in the wizard, since it's just a number.  
> 
> So I'm trying to write a query to also select the email address and return 
> it in my results... without any luck so far.  I'm getting sql syntax errors.  
> Here's the kind of query I'm attempting:
> 
> SELECT GroupName, Primary, 
>  (select Contacts.[E-mail Address] where Contacts.ID = Primary)
> FROM Groups;
> 
> suggestions for a newbie?  thanks
0
Utf
12/13/2009 6:54:02 PM
Thanks, Duane.  My table design was an attempt (possibly incorrect) to 
normalize things.  Here's what I'm doing:

-starting with the contacts template, with several hundred records,  from 
Office 2007.  That part is mostly dandy.
-added a second "groups" table... I have 40 groups, each with up to 10 
members.  We have a primary contact, that "owns" the group content.  I need 
to mail out to them the list of names in their group to verify that I have 
the right people.  Once I update the table with their email replies, then I 
use the contacts table to verify all the details for each person in one or 
more groups.   Since 1 person can belong to multiple groups, I was just 
trying to save the "id" (key) field that represents that person in the groups 
table, so that I wouldn't have all this information duplicated.

But this means that when I create the form to email out to the groups 
owners, I need to resolve all those ID numbers into email addresses for them 
to confirm.  In thinking further though, if they make a change (eg: add 
another email address to their group), then that's not going to be much good, 
as the update logic when I process their return email won't know how to 
insert that new record into the contacts table anyway (plus, I'd need to 
modify the changed groups entry to repopulate it with contact ID numbers 
anyway.)

Perhaps I should give up and just maintain actual email addresses in the 
groups table and stop trying to (badly) normalize the tables by using an ID 
number?

I wonder if creating a view might help instead?  So much for my amateur 
attempts to normalize!  Thanks for the help.

"Duane Hookom" wrote:

(snip)
> Also, if you multiple contact fields in the Groups table, yhou might want to 
> consider normalizing your table structures.
> 
> -- 
> Duane Hookom
> Microsoft Access MVP
> 
> 

0
Utf
12/14/2009 11:59:01 AM
You should have one table with the PersonID and PersonEmail. Then another 
table of groups with one record per group and fields like GroupID and 
GroupTitle. A third table would be the junction table which would contain one 
record per group per person and have at least these two fields:
   PersonID
   GroupID

-- 
Duane Hookom
Microsoft Access MVP


"Slushpump" wrote:

> Thanks, Duane.  My table design was an attempt (possibly incorrect) to 
> normalize things.  Here's what I'm doing:
> 
> -starting with the contacts template, with several hundred records,  from 
> Office 2007.  That part is mostly dandy.
> -added a second "groups" table... I have 40 groups, each with up to 10 
> members.  We have a primary contact, that "owns" the group content.  I need 
> to mail out to them the list of names in their group to verify that I have 
> the right people.  Once I update the table with their email replies, then I 
> use the contacts table to verify all the details for each person in one or 
> more groups.   Since 1 person can belong to multiple groups, I was just 
> trying to save the "id" (key) field that represents that person in the groups 
> table, so that I wouldn't have all this information duplicated.
> 
> But this means that when I create the form to email out to the groups 
> owners, I need to resolve all those ID numbers into email addresses for them 
> to confirm.  In thinking further though, if they make a change (eg: add 
> another email address to their group), then that's not going to be much good, 
> as the update logic when I process their return email won't know how to 
> insert that new record into the contacts table anyway (plus, I'd need to 
> modify the changed groups entry to repopulate it with contact ID numbers 
> anyway.)
> 
> Perhaps I should give up and just maintain actual email addresses in the 
> groups table and stop trying to (badly) normalize the tables by using an ID 
> number?
> 
> I wonder if creating a view might help instead?  So much for my amateur 
> attempts to normalize!  Thanks for the help.
> 
> "Duane Hookom" wrote:
> 
> (snip)
> > Also, if you multiple contact fields in the Groups table, yhou might want to 
> > consider normalizing your table structures.
> > 
> > -- 
> > Duane Hookom
> > Microsoft Access MVP
> > 
> > 
> 
0
Utf
12/15/2009 4:27:01 AM
Appreciate the guidance, Duane... the lightbulb is starting to come on!  My 
guess, however is that convincing the "contacts template" to work with 3 
tables and properly perform updates to the correct places might be a larger 
challenge than I'm capable of solving, given my newb knowledge level.

Unless anyone has any obvious miracle cures, I think I'll revert to an out 
of the box contact template and add a groups table... then will manually 
manage the relationships and updates.... This will meet my immediate need, 
although more manually intensive than I'd hoped.  It'll also stop me from 
consuming more than my fair share of the discussion group bandwidth... :-)

If there's any apps I could purchase to do this, I'd be happy to take a 
look.. but Mr. Google hasn't coughed any up so far that seem to do this.

thanks again....

"Duane Hookom" wrote:

> You should have one table with the PersonID and PersonEmail. Then another 
> table of groups with one record per group and fields like GroupID and 
> GroupTitle. A third table would be the junction table which would contain one 
> record per group per person and have at least these two fields:
>    PersonID
>    GroupID
> 
> -- 
> Duane Hookom
> Microsoft Access MVP
> 
> 
> "Slushpump" wrote:
> 
> > Thanks, Duane.  My table design was an attempt (possibly incorrect) to 
> > normalize things.  Here's what I'm doing:
> > 
> > -starting with the contacts template, with several hundred records,  from 
> > Office 2007.  That part is mostly dandy.
> > -added a second "groups" table... I have 40 groups, each with up to 10 
> > members.  We have a primary contact, that "owns" the group content.  I need 
> > to mail out to them the list of names in their group to verify that I have 
> > the right people.  Once I update the table with their email replies, then I 
> > use the contacts table to verify all the details for each person in one or 
> > more groups.   Since 1 person can belong to multiple groups, I was just 
> > trying to save the "id" (key) field that represents that person in the groups 
> > table, so that I wouldn't have all this information duplicated.
> > 
> > But this means that when I create the form to email out to the groups 
> > owners, I need to resolve all those ID numbers into email addresses for them 
> > to confirm.  In thinking further though, if they make a change (eg: add 
> > another email address to their group), then that's not going to be much good, 
> > as the update logic when I process their return email won't know how to 
> > insert that new record into the contacts table anyway (plus, I'd need to 
> > modify the changed groups entry to repopulate it with contact ID numbers 
> > anyway.)
> > 
> > Perhaps I should give up and just maintain actual email addresses in the 
> > groups table and stop trying to (badly) normalize the tables by using an ID 
> > number?
> > 
> > I wonder if creating a view might help instead?  So much for my amateur 
> > attempts to normalize!  Thanks for the help.
> > 
> > "Duane Hookom" wrote:
> > 
> > (snip)
> > > Also, if you multiple contact fields in the Groups table, yhou might want to 
> > > consider normalizing your table structures.
> > > 
> > > -- 
> > > Duane Hookom
> > > Microsoft Access MVP
> > > 
> > > 
> > 
0
Utf
12/15/2009 3:10:02 PM
Reply:

Similar Artilces:

Timer for Queries?
Does anyone know of a macro or add-on that I could use as a simple timer for queries? I don't like to use the CPU time in the Task Manager because of it's inaccuracy when not receiving full CPU usage. THanks for any suggestions -- cmungs Exactly what are you trying to accomplish? Are you trying to cause a query to run automatically every so often? If so, you will need to use the timer event on a form to do that. -- Lynn Trapp Microsoft MVP (Access) www.ltcomputerdesigns.com "cmungs" <cmungs@discussions.microsoft.com> wrote in message news:88EC7019-045F-4EF...

Erratic results from query criteria
I am getting different results from running the same query with the same selections. One moment it is all behaving as expected, the next it has gone haywire. (I have done what appears to me to be EXACTLY what I have done in another database, where it works perfectly every single time.) In a query I have, amongst others, the following fields: Category SubCategory Company I want to be able to select any OR ALL of the relevant fields. I have the following criteria: Like "*"&[Type Category otherwise leave blank for ALL]&"*" Like "*"&a...

Problem moving multiple items after .pst import
Hi, I imported a users .pst to our Exchange 5.5 Server via Outlook2k. After this he cannot move or delete multiple items without getting Outlook to hang (single items work just fine). Works fine using the OWA, though... Would you say this is a IS (or Exchange) problem or Outlook client error? Rgds :// Thomas Run Performance Optimizer (perfwiz.exe) on your Exchange machine. Thomas Arcclight wrote: > Hi, > I imported a users .pst to our Exchange 5.5 Server via > Outlook2k. > After this he cannot move or delete multiple items without > getting Outlook to hang (single items ...

Office Discussion Groups search problem
It appears that the search function is not returning any posts from 2010. Does anyone know how to bring this to Microsoft's attention? Thanks, Bruce Realistically, all Microsoft's done is put a (pretty poor) web interface onto existing NNTP newsgroups. This particular group is microsoft.public.access Try using http://groups.google.com/advanced_search -- Doug Steele, Microsoft Access MVP http://www.AccessMVP.com/DJSteele (no e-mails, please!) "Brucels" <Brucels@discussions.microsoft.com> wrote in message news:4EB79950-F1CC-4205-92D9-56233E8E676...

how to assign color for a data type
Hi i have made a chart for sales of 12 items in 28 outlets over a period of 4 years (ie total sale for the year), not all outlets have all 12 items. the outlest only stock what they think they can sell. so they may have sold an item one year, and not sold it next year. when I make a bar chart for each outlet I have 4 bars, one for each year, and each item is stacked up on the other on the bar, now only problem is that when i select another store, the bars all change colors, as in even if item 7 were there in both shops, the color representing item 7 is diffrent. In other words, irrespective o...

Update Query ?
Is there a way to 1) Assign events when adding in data thru an update query for example if you append a bunch of data into a table could you then do some kind of an update query to say if there is an initial event and no others tag this one Renewal 1 etc.. the only real data you have to go on would be Customer A and the total amt .. the event, renewal event and the delta would all need to be added in example: Say Customer A comes in with an initial deal then Customer A renews their deal So, the data would look like when you're done.: Year Custo...

design query match anywhere?
In the design query I want to match the letters "ABC" anywhere in the column 'description'. I could not get instr to work by using: InStr(description, "ABC")) > 0 How else can I match ABC (upper and lowercase) to anywhere in my 'description' column? Thanks! Are you saying you put that InStr bit as a criteria under your Description field in the query designer? Try putting Like "*ABC*" as the criteria instead. Alternatively, you could add a computed field to the query InStr([Description, "ABC") and then put >0 as the ...

MDI childframe problems
To create a maximized mdi child frame I tried this: BOOL CChildFrame::PreCreateWindow(CREATESTRUCT& cs) { if( !CMDIChildWnd::PreCreateWindow(cs) ) return FALSE; if (IsWindow(m_hWnd)) { ShowWindow(SW_SHOWMAXIMIZED); } return TRUE; } The window is opened maximized but the minimize/maximize/close buttons are missing. When I open a 2nd document and click on windows | tile the behaviour turns back to normal. Can someone tell what's wrong here? cs.style |= WS_MAXIMIZE didn't work either. It's opened in normal size. TIA, Hans Do this in ActivateFrame: void CChildFrame...

field highlight
i have an account spreadsheet. with a column heading reading status. How can i tell excel to highlight all cells containing status "I" fo inactive in red, and status "A" for active in green -- Message posted from http://www.ExcelForum.com You would use Format>Conditional Formatting for this. Select the column in question(I'll assume A). Format>Conditional Formatting>Formula is: enter =A1="I" Format>Pattern Red>OK Add =A1="A" Format>Pattern Green>OK Note: you can use up to three conditional formats(four if you count...

Unexpected Error- Running Advance Find Query
I am getting a message that says "Unexpected Error An Error has occurred" when I am running an advanced find query on two custom entities. It seems to be when I have certain custom fields included in my view that the query errors out. Any help on this would be greatly appreciated. Thanks so much. Just wanted to add that I seem to get errors when there is a 0.00 amount in these fields... "TJ" wrote: > I am getting a message that says "Unexpected Error An Error has occurred" > when I am running an advanced find query on two custom entities. It se...

Problems importing from DBF to Outlook
I've been importing records from my business database (Foxpro DBF) to Outlook's Contacts database for about a week and have run into a snag. One of the fields contains the contact's email address, and although it appears to import over to Outlook with no trouble, when I highlight a given Outlook record and select the New Message to Contact icon, I get the following error: "Error creating new mail! This may be caused due to an incorrect e-mail address for a contact or an invalid name for a distribution list." Since I have no distribution list, I assume the problem inv...

weird WM_QUERYENDSESSION problem
Recently, I had a problem reported to me with (non-admin) operators unable to log out of our server systems. I tracked this down to the "Default IME" window associated with several applications (different each time) responding to WM_QUERYENDSESSION with FALSE. I went to the trouble of writing a test app that enumerated top-level windows and sent them this message just so I could check. Imagine my suprise when I found it wasn't even a window that we'd created for ourselves that caused the problem. Now we can fix this problem by turning off advanced text input services, becau...

pass through query
If a combobox is populated by a pass-through query, does it requery every time the form is closed and reopened? Thanks, Sam Yes. John Spencer Access MVP 2002-2005, 2007-2010 The Hilltop Institute University of Maryland Baltimore County Sam wrote: > If a combobox is populated by a pass-through query, does it requery every > time the form is closed and reopened? > Thanks, > Sam ...

Removing a field From a Pivot Table
I'm working with a pvt table in excel. Right now there are several fields in the pvt table, including the month different entries are made and the account that made them. When i hit the show detail button in the pivot table i get the detail all of the entries grouped by month and by account on a separate sheet. I want to continue to do this, but i want to also be able to get a second view where i hit the show detail button and only see the detail grouped my account (month is either hidden or totally removed from this list of data in the pvt table and the rows that composed the different...

a count field in a query?
Hello, I have a query in which I would like to create a field which increments by 1 for each record selected, so if there are 10 records selected by the query, this column would show numbers 1 to 10. Ideally I would like to have some text in front of each number, say invoice1, invoice2 etc. From a previous posting I realise that this is frowned upon but it would be the simplest solution for my problem! How can I do this? Thanks Geoff On Mon, 03 Dec 2007 08:54:00 +0000, Geoff Cox <<>> wrote: >Hello, > >I have a query in which I would like to create a field which >...

Saving Username and Pass with Web Queries
I am pulling data from a website that requires you to provide a usernam and password everytime you visit the site. Excel has cachin capabilities, but everytime you close excel and try and open up th spreadsheet again, it can't login. What is the fix for this? Thanks, Hend -- Message posted from http://www.ExcelForum.com Bump! --- Message posted from http://www.ExcelForum.com/ ...

why does Word display my field codes upon opening?
I am using Office 2007, and version 11 of Reference Manager. When I open my document, both the Reference Manager fields and the page numbers display with the cryptic words in [brakets]. I must Select All and 'toggle field codes' every time. Can I have Word open with the fields already 'toggled'? Office Button>Word Options>Advanced then uncheck the "Show field codes instead of their values" in the Show document content section of the Word Options dialog. -- Hope this helps, Doug Robbins - Word MVP Please reply only to the newsgroups unle...

Birthday query for many children in one record
I have a database for the church, it has one main flat table only. Each record for the parents have field for child1 name, child1birthday, child2 name, child2birthday, child3 name, child3birthday - up to 5 children. I am having difficulty trying to get a report to list the birthdays of the children like this parent name, child 1 name, child 1 birthday month etc. so you get something like this:- Parent John Smith, child Mary Smith January 3 Parent Fred Jones, child Bert Jones March 4 Parent John Smith, child Jane Smith March 6 Parent Harry Brown, child Jane Brown March 6 Parent Bert Taylor,...

Space problem with .NET 2.0
I am loading an XML file and applying the XSLT using .net 2003 (C#). XSLT will add Space character in the xml. I am using the entity value for space character &#32. it works fine in .net 1.1 whereas in .net 2.0 the space character is not showing up in the xml at all. Any idea why this works in ..NET 1.1 and not the .NET 2.0 parser? However, if I use the entity (&#160) then it works well for both .net 1.1 and .net 2.0. Is this a known issue? Any suggestions on why the space is not showing up with .NET 2.0 would be appreciated. Gaurav wrote: > I am loading an XML file and ap...

local and external address problem
Hello I've got one problem with exchange 2000 At configuration Outlook 2000 with use Exchange Serwer and outisde mail account. During sending a massages in this outside account(it's a default mail box), massage was marked as exchange local name (for example user@exchange.local) In result the receiver see local address and don't know what is sender external account (address) When I try force sending massage with external address (in field from) exchange write the error " you have no permission to send massage uses this account". How can we resolve this? Thanks for he...

Unresponsive Query Wizard
Hi there, I have an Excel 2003 user who is using a spreadsheet that pulls data from our SQL server. When he opens it and refreshes the data it is fine, it pulls the current data, but when he tries to edit the query, the Query Wizard does not appear, he can see it on the task bar, but when he switches focus using task manager everything is greyed out and nothing works. I have tested the file from my computer and it is fine, which suggests a problem with his machine or installation. Does anyone have any ideas? Cheers, Steve Dooza wrote: > Hi there, > I have an Excel 2003 user who...

Money Login Problems
I was unable to login using passport to retrieve my *.mny file after 3 years of flawless use. Then about 12/22/07 was unable to access the file using Money 2004. I went through the gyrations of chainging my password on my passprt account, etc. even though it would log in outside of Money, but to no avail. I then upgraded to Money Plus Deluxe in an effort to resolve the issue, but again to no avail. I am even unable to access the file off-line with the Money password for the account. After reading your posts here I realize many of you are experiencing the same problem. Any insight ...

Another simple query
Dear all, I have a table that contains first names and last names in different fields. Is there any way to write a query that will give as a result the first name and last name in the same field? I hope this makes sense. Thanks in advance! SELECT [last_name_field] & ", " & [first_name_field] AS whole_name FROM [your_name_table] Change the field and table names to whatever your actual fields and tables are. Cheers, Jason Lepack On Apr 23, 9:47 am, Homer <peter.a.r...@googlemail.com> wrote: > Dear all, > > I have a table that contains first names an...

Query query
I am trying to create a new field in which it shows the sum total of 10 fields (Charge Time, Charge Time 2, Charge Time 3, etc.); what is the easiest way to do this? -- Joe NewFieldName: [Charge Time] + [Charge Time 2] + [Charge Time 3] .... etc -- Good Luck BS"D "joet5402" wrote: > I am trying to create a new field in which it shows the sum total of 10 > fields (Charge Time, Charge Time 2, Charge Time 3, etc.); what is the easiest > way to do this? > -- > Joe I tried this, and it doesn't work. Is there something I'm forgetting? -- Joe ...

Problem -- Personal.XLS is being modified message keeps poping up.
When I open any workbook using Excel 97 and then try to open another instance of Excel, I always get a message saying something like, " Personal.xls is being modified by 'me' ." I certainly am not deliberately modifying personal.xls. When I change its attribute to 'read only' this does not happen. Can someone tell me what might be causing this message by trying to modify personal.xls and what I can do about it? Thank you. A follow on to this problem. With no other instance of Exel running that I am able to detect, if I try to open personal.xls, I get a message...