Insert QRY results into existing table/records

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • artemetis
    New Member
    • Jul 2007
    • 76

    Insert QRY results into existing table/records

    Ok, here's another........ .I've done it in the past, but am sick as dog right now and am not thinking properly..

    I have an XLS that has the following info empUid, empStat, empPerf1, empPerf2, empPerf3.

    The file gets emailed, updated then needs to be imported back into MDB table, respective fields.

    Opening query, have the file linked, but I am completely forgetting how I inserted the information into the proper existing empUID (essentially updating their empty fields), rather than having it added to the end of the table?

    PULLING MY LAST BITS OF HAIR OUT!
  • Stewart Ross
    Recognized Expert Moderator Specialist
    • Feb 2008
    • 2545

    #2
    Hi. You could try the following update statement which updates the fields of the table joined to the Excel linked table. You must substitute in the correct names of your access table and your linked excel table as appropriate.

    Code:
    UPDATE     [your access table]       AS A 
    INNER JOIN [your linked excel table] AS E ON
               A.EmpUID   = E.EmpUID
    SET        A.empStat  = E.empStat, 
               A.empPerf1 = E.empPerf1, 
               A.empPerf2 = E.empPerf2, 
               A.empPerf3 = E.empPerf3;
    -Stewart

    Comment

    • artemetis
      New Member
      • Jul 2007
      • 76

      #3
      Thanks Stewart!
      Worked like a charm....
      Now, one last "stupid" question......i f, on the XLS, I would like to have "Employee Performance in Area 1" as the column heading, rather than empPerf1, is that possible?

      You know, those outside....look ing at the XLS need it to be pretty. :o)

      Comment

      • Stewart Ross
        Recognized Expert Moderator Specialist
        • Feb 2008
        • 2545

        #4
        Hi Art. You can set the Excel headings in any suitable way, then refer to them in the update SQL like this:

        Code:
        A.empPerf1 = E.[Employee Performance in Area 1]
        It is essential to use the left and right square brackets to enclose any field name that contains spaces.

        -Stewart

        Comment

        • artemetis
          New Member
          • Jul 2007
          • 76

          #5
          Wooo-Hooo!
          Worked like a charm!!!
          Thanks and thanks to all that chimed in to help me out with this post.
          :o)

          Comment

          • artemetis
            New Member
            • Jul 2007
            • 76

            #6
            So....like I said above, this worked beautifully.

            Now I'm just wondering if there is a way to be prompted for the the source table at qry execution? Or is this something that needs to be built into a form?

            Code:
            UPDATE     [PROMPT FOR TABLE???]       AS A 
            INNER JOIN [your linked excel table] AS E ON
                       A.EmpUID   = E.EmpUID
            SET        A.empStat  = E.empStat, 
                       A.empPerf1 = E.empPerf1, 
                       A.empPerf2 = E.empPerf2, 
                       A.empPerf3 = E.empPerf3;
            I'm thinking something along these lines.....

            Code:
            SELECT MSysObjects.Name
            FROM MSysObjects
            WHERE (((MSysObjects.Type)=1) AND ((MSysObjects.Name) Like "*tbl*")) OR (((MSysObjects.Type)=6) AND ((MSysObjects.Name) Not Like "*~TMPCLP*"))
            ORDER BY MSysObjects.Name;
            Last edited by artemetis; Jan 14 '09, 02:14 PM. Reason: Adding some info...

            Comment

            • ChipR
              Recognized Expert Top Contributor
              • Jul 2008
              • 1289

              #7
              Check out Everything About Using Parameters from Code. If you do this, you will probably want to make a form because the msg box asking for the parameter is so ugly and limited.

              Comment

              • artemetis
                New Member
                • Jul 2007
                • 76

                #8
                Thanks for all the help!
                Worked beautifully using a form and the DoCmd :o)

                Comment

                Working...