Page 1 of 3 123 LastLast
Results 1 to 15 of 36
  1. #1
    diane802 is offline Advanced Beginner
    Windows XP Access 2007
    Join Date
    Dec 2009
    Posts
    92

    Query result based upon two field conditions

    If I have two tables.



    One shows First Name, and Last Name as two separate fields.

    Second shows First Name and Last name in one field, with a space separating. The second table has information on it, that I want to relate back into the first table.

    How can I combine these two?

    How i did it was, I created a query which concatenates First Name and Last name, into a new control field called Full Name. I created a join relationship between Full Name, and the Second Table's primary key "Full Name".

    I then created a second query, which brings in the Full Names, and then the related information in the table #2.

    However - in this second query, i am unable to actually update say the First and Last Name at all - and have it autopopulate the table #2 updated data. It says I cannot update the recordset.

  2. #2
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows XP Access 2002
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    Typically you would only put the PrimaryKey of the 1st table in the 2nd table as a ForeignKey. Then you can display whatever you want whenever you want.

  3. #3
    diane802 is offline Advanced Beginner
    Windows XP Access 2007
    Join Date
    Dec 2009
    Posts
    92
    The query is displaying the results - however, it won't let me in this query, say change the First name from Michael to Mary, and show me the updated result. I woul need to update the First name in the main table, or in query #1 first, and then run this query.

    This query says I cannot edit the record.

  4. #4
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows XP Access 2002
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    This link should help explain that issue.

  5. #5
    diane802 is offline Advanced Beginner
    Windows XP Access 2007
    Join Date
    Dec 2009
    Posts
    92
    I have been reading over that site several times.

    I think my issue is "The fields in a JOIN are not indexed correctly: there is no primary key or unique index on the JOINed fields."

    Query#2 which combines First and Last Name, does not have a "primary key" - can I identify a primary key within a query? Right now, it just links to Table #2's Full Name.... I noticed that if I set the query #3 that I am in, to "Dynaset (inconsistent updates)" - it lets me alter the first and last name separately, but it does not update the "Full Name" from Table #2... it does update it in the concatenated version in query #2.

  6. #6
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows XP Access 2002
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    When truly normalized, the first and last name are only in one table. All of the other tables that need this value just use a FK to the other table.

  7. #7
    diane802 is offline Advanced Beginner
    Windows XP Access 2007
    Join Date
    Dec 2009
    Posts
    92
    sorry - not sure I understand, so in my table #1, I have first and last name only in that table.

    Let's say I need to combine the two in order to use this combination - to look up information from table#2 - where the primary key is one field that has First and Last name combined - what do I do?

  8. #8
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows XP Access 2002
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    Are you in control of the structure for table #2?

  9. #9
    diane802 is offline Advanced Beginner
    Windows XP Access 2007
    Join Date
    Dec 2009
    Posts
    92
    yes - i am.

  10. #10
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows XP Access 2002
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    Then my post #6 still applies. What you want can be done but you will struggle with problems. Can you add an AutoNumber field as a PK and a LongInteger as a FK (which points to a record in table #1) and remove the First and Last name from this table?

  11. #11
    MAF4Fam6's Avatar
    MAF4Fam6 is offline Advanced Beginner
    Windows XP Access 2007
    Join Date
    Dec 2009
    Location
    Fruit Heights, Utah USA
    Posts
    140

    Post Query result based upon two field conditions

    I completely agree with RuralGuy.
    Without a Primary Key other the member's Full Name (i.e. Social Security Number, CustomerID, EmployeeID, etc.) you will more than likely run into problems, particularly in your queries. The possibilty exists between your two tables to have more than one person with the same first and last name, not to mention inconistencies between the same record in two tables with different spellings of first names due to long names, short names, or nicknames.

    -RC

  12. #12
    diane802 is offline Advanced Beginner
    Windows XP Access 2007
    Join Date
    Dec 2009
    Posts
    92
    MAF4Fam6 and RuralGuy - you both make complete sense.

    But what if in this table, I have fields such as City and Job Function, and the combination of the two lead me to determine the Business they sit in.

    So I have Table #1 which has all the main employee including City and Job Function (in two separate fields). And then I have Table #2 - which shows the aligned business is lets say City is new York, and Job Function is Sales.

    How would you go about creating the lookup?

    Right now, I created a query that combines City and Job Function into one field (ie New York / Sales). In Table #2, I already have a field in there that shows New York / Sales that is the primary key. When I do a second query to do the lookup, this second query is automatically marking as RecordSet Not Updateable - unless i change the record type to Dynaset (inconsistent updates). However, if I do this - I need to actually hit "Refresh All" on the home button, in order to have the record refresh.

  13. #13
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows XP Access 2002
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    I'm sorry Diane, but create a lookup for what? What are you trying to lookup in Table#2? Why do you have a text field that contains "New York / Sales" as a primary key. Were you just trying to let Access eliminate duplicates?

  14. #14
    diane802 is offline Advanced Beginner
    Windows XP Access 2007
    Join Date
    Dec 2009
    Posts
    92
    Basically, table#2 shows City, Function - and then it aligns to a Business.

    So lets say in Table #1, I show that a person sits in New York, and there function is Sales. Table #2 will tell us that they work in New York Distribution.

    For every City and Function combination - there is only one match to a Business.

    So I want to look up this Business Name for each individual.

    I made that text field a primary key in Table #2 - because that is unique, and there are no duplicates.

  15. #15
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows XP Access 2002
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    Does table #2 have a 1:1 relationship with table #1?

Page 1 of 3 123 LastLast
Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 1
    Last Post: 11-10-2009, 03:20 PM
  2. Programming a result field in a table
    By Linda in forum Programming
    Replies: 9
    Last Post: 07-13-2009, 08:07 PM
  3. Query on multipl conditions.
    By Goldenbird in forum Queries
    Replies: 0
    Last Post: 06-28-2009, 11:45 PM
  4. query - criteria based on another row field value
    By techexpressinc in forum Queries
    Replies: 1
    Last Post: 05-29-2009, 04:17 PM
  5. Replies: 0
    Last Post: 04-17-2008, 09:24 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums