Results 1 to 5 of 5
  1. #1
    jrbmagoo is offline Novice
    Windows 10 Access 2010 32bit
    Join Date
    Aug 2016
    Posts
    2

    Update Syntax

    Good Day - I'm working on a form to assign work in Access. I have all of the other pieces set up besides this last part. So the first part of the form the supervisor would select the type of work they want to assign from a drop down. I linked the form to my query to pull the work (Priority) that does not have any attempted calls made. That works fine. Next the sup selects who they want to assign the work to (CID) from a drop down. The last part is where it gets a little tricky. The last option on the form for the sup to select is the number of records they want assigned to the CID they have selected based on the priority. What I would like the update query to do is assign the CID to the records that were pulled by Priority based off what ever number the sup enters into the box on the form. So if they have selected TOU as the priority and CID 01234 as the rep they want to assign work to and 20 in the quantity box, I want the update to take 20 records that fit the criteria and assign to that rep. Any assistance you guys can provide would be greatly appreciated.

  2. #2
    Bulzie is offline VIP
    Windows 7 64bit Access 2007
    Join Date
    Nov 2015
    Posts
    1,511
    Maybe something like this: (AfterUpdate on the form

    rs1 = Select * From AssignmentTable Where Priority = '" & Me.Priority & "' And Attempted Calles = null"

    rs1.MoveFirst
    For x = 1 to me!Quantity
    rs1.Edit
    rs1!CID = me!CID
    rs1.Update
    Next x

  3. #3
    John_G is offline VIP
    Windows 7 32bit Access 2010 32bit
    Join Date
    Oct 2011
    Location
    Ottawa, ON (area)
    Posts
    2,615
    You have to account for the fact that there might not be enough records to assign, i.e. the quantity requested might be too large. A few changes to the code can look after that:

    Code:
    rs1 = Select * From AssignmentTable Where Priority = '" & Me.Priority & "' And nz([Attempted Calls],0) = 0"   ' because it might be Null or 0
    
    rs1.MoveFirst
    x = 1
    While x <= me!Quantity and not rs1.EOF
    
    rs1.Edit
    rs1!CID = me!CID
    rs1.Update x = x + 1 rs1.Movenext ' advance to the next record
    Wend
    This assumes that you don't really care which records are assigned; Access will not put the results into rs1 in any particular order.

  4. #4
    jrbmagoo is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Aug 2016
    Posts
    2
    I'm thinking of making this action execute from a button, so would be On Click for the event. Will the code above execute this based off the options selected in the form?

  5. #5
    John_G is offline VIP
    Windows 7 32bit Access 2010 32bit
    Join Date
    Oct 2011
    Location
    Ottawa, ON (area)
    Posts
    2,615
    As long as the Command Button is on the same form as the Quantity and CID options, it should work. If the record source for the form is AssignmentTable and one of the records the code tries to update is the one currently on the screen, you might get an error about another user trying to update the record.

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

Similar Threads

  1. Complex Update syntax
    By ricksil in forum Queries
    Replies: 3
    Last Post: 12-07-2015, 08:15 AM
  2. SQL Update Syntax Error
    By Phred in forum Queries
    Replies: 9
    Last Post: 02-05-2012, 05:56 PM
  3. Update syntax
    By looloo in forum Programming
    Replies: 6
    Last Post: 09-23-2011, 07:58 PM
  4. sql UPDATE syntax help
    By ducthang88 in forum Programming
    Replies: 1
    Last Post: 12-04-2010, 12:12 PM
  5. Syntax For After Update Event
    By MuskokaMad in forum Forms
    Replies: 14
    Last Post: 03-12-2010, 01:48 PM

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