Results 1 to 3 of 3
  1. #1
    newbieX is offline Competent Performer
    Windows 7 64bit Access 2007
    Join Date
    Jul 2013
    Posts
    111

    Modify SQL code after splitting name into two fields

    I am not sure how to modify this SQL to get the same results when I try to substitute the field "Name" with two fields "FirstName" and "LastName"



    Code:
    SELECT t1.Name, t1.Title, t1.Address, t1.City, t1.State, t1.ZipCode, t1.[Contact Number], t1.Email, t1.Organization, t1.[Date Received]
    FROM Orders AS t1
    WHERE (((t1.Organization)=[Forms]![frmProducts]![cboOrganization]) AND ((t1.[Date Received])=(SELECT Max(t2.[Date Received]) FROM Orders t2 WHERE t2.Name=t1.Name GROUP BY t2.Name)));
    I have an SQL that basically selects a bunch of fields from the Orders table where the selection in the form's combo box "Organization" equals the Organization name in the Orders table. It is grabbing the most recent contact information of all personnel that worked at that organization based on their latest order date. It auto-populates the form with this information. This SQL is on the Row Source of Names combo box on the products form.

    It works fine but I have decided to split the name field out into two fields, FirstName and LastName. How can I group by these two fields which would have to probably be concatenated together to get the correct results. Thus the t1.Name would have to substituted with "t1.FirstName & t1.LastName" and the same for t2.Name in the SQL statement above.

    Suggestions from Access guru gods?

    Using Access 2010

  2. #2
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,549
    Change the word t1.name to
    t1.FirstName, t1.Lastname

  3. #3
    CJ_London is offline VIP
    Windows 8 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,841
    matching by name is fraught with problems - what if you have two people with the same name, or someone gets married and changes their name? Don't you have an autonumber or some other unique field?

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 6
    Last Post: 09-10-2014, 01:15 PM
  2. Modify D/T for Multiple Fields in the Record
    By Murphy0417 in forum Access
    Replies: 8
    Last Post: 07-02-2014, 11:40 AM
  3. How to modify code to open report instead of form
    By kassem in forum Programming
    Replies: 4
    Last Post: 06-10-2014, 07:02 PM
  4. SQL*Plus code in MsAccess, how to modify?
    By suverman in forum Queries
    Replies: 1
    Last Post: 05-20-2011, 07:01 AM
  5. Word code in Access - How to modify my current code
    By Alexandre Cote in forum Programming
    Replies: 0
    Last Post: 11-15-2010, 08:26 AM

Tags for this Thread

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