Results 1 to 3 of 3
  1. #1
    doomy304 is offline Novice
    Windows 7 64bit Access 2010 32bit
    Join Date
    Jun 2011
    Posts
    6

    Update query issue

    Hello,

    I am very very new to Access, so apologies if I get terminology wrong or make silly mistakes - I'm trying to self-teach with the help of tutorial books and the internet.

    I have a database, with an Users table (containing LastName, FirstName, and Manager fields) and a MgmtNames table. The managers have divided up the agents by last name - there are four managers, the first one gets everyone with last names A through C, the second gets D through L, etc. What I would like is for the Manager field in the Users table to auto-populate the correct manager name when I add a new record to the Users table. The Manager field is numerical and linked to the ID field in the MgmtNames table.



    So I thought the best way to do this would be via update query. I cleared any existing data out of the Manager fields in advance of running the query. The first time I set it up, it previewed just fine, but when I tried to run it, it made no changes and gave me no error messages. It would not run/preview on any fields after that, UNLESS there is something in the Manager field already, and in that case the preview only shows me whatever is already in the Manager field. I even deleted the query and recreated it (in case all the fields that got "updated" the first time were now flagged as "query has already run on these fields" or something like that) and still nothing.

    Here is the SQL code:

    UPDATE MgmtNames INNER JOIN Users ON MgmtNames.ID = Users.Manager SET Users.Manager = Switch([LastName] Like "[A-C]*",1,[Lastname] Like "[D-L]*",2,[LastName] Like "[M-R]*",3,[LastName] Like "[S-Z]*",4);

    What am I doing wrong? Thanks in advance for any help!

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,943
    Don't see need for the join. Switch function is new to me. Actually works! Try:
    UPDATE Users SET Manager = Switch(Left([LastName],1) Like "[A-C]",1,Left([Lastname],1) Like "[D-L]",2,Left([LastName],1) Like "[M-R]",3,Left([LastName],1) Like "[S-Z]",4);
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    doomy304 is offline Novice
    Windows 7 64bit Access 2010 32bit
    Join Date
    Jun 2011
    Posts
    6
    Quote Originally Posted by June7 View Post
    Don't see need for the join. Switch function is new to me. Actually works! Try:
    UPDATE Users SET Manager = Switch(Left([LastName],1) Like "[A-C]",1,Left([Lastname],1) Like "[D-L]",2,Left([LastName],1) Like "[M-R]",3,Left([LastName],1) Like "[S-Z]",4);
    THAT DID IT! Thank you so much!!

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

Similar Threads

  1. Update 2 tables with one Update Query
    By Douglasrac in forum Queries
    Replies: 4
    Last Post: 04-14-2011, 08:33 AM
  2. Back color update issue
    By GraemeG in forum Programming
    Replies: 3
    Last Post: 03-21-2011, 11:32 AM
  3. Current Record Update Issue
    By SALPBE in forum Programming
    Replies: 0
    Last Post: 02-23-2011, 03:02 PM
  4. Update Query Performance Issue
    By Amber_1977 in forum Queries
    Replies: 2
    Last Post: 12-07-2010, 08:36 AM
  5. Update Query- selective update?
    By stephenaa5 in forum Queries
    Replies: 1
    Last Post: 10-29-2009, 11:15 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