Results 1 to 3 of 3
  1. #1
    behnam is offline Advanced Beginner
    Windows 7 32bit Access 2010 32bit
    Join Date
    May 2014
    Posts
    72

    How to Increment an integer field by one using currentdb.execute

    Code:
    CurrentDb.Execute "UPDATE TimeHandle SET [counter] = [counter] +1 WHERE [agent] = " & gsUser
    the code above is suppose to increment a counter in the table Timehandle by 1 wherever the agent field is equal to the value stored in a global variable called gsUser. Does anyone know what is wrong with the syntax, thanks.

  2. #2
    JoeM is offline VIP
    Windows XP Access 2007
    Join Date
    Jun 2012
    Posts
    3,904
    Is Agent a string or numeric field?
    If it is a string (text), you need text qualifiers (of single quotes), i.e.
    Code:
    CurrentDb.Execute "UPDATE TimeHandle SET [counter] = [counter] +1 WHERE [agent] = '" & gsUser & "'"
    Last edited by JoeM; 03-30-2015 at 10:35 AM. Reason: word got chopped off

  3. #3
    behnam is offline Advanced Beginner
    Windows 7 32bit Access 2010 32bit
    Join Date
    May 2014
    Posts
    72
    Thanks, worked perfectly.

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

Similar Threads

  1. vba code help - Currentdb.execute
    By joycesolomon in forum Programming
    Replies: 5
    Last Post: 08-11-2014, 11:25 AM
  2. Replies: 12
    Last Post: 01-24-2014, 02:18 PM
  3. Problems with CurrentDb.Execute "UPDATE
    By GraeagleBill in forum Programming
    Replies: 4
    Last Post: 04-06-2013, 03:21 PM
  4. Update sql using currentdb.execute
    By laavista in forum Access
    Replies: 13
    Last Post: 08-15-2011, 03:51 PM
  5. Get Field names from a table in CurrentDB()
    By e.badin in forum Programming
    Replies: 8
    Last Post: 01-06-2011, 02:17 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