Results 1 to 3 of 3
  1. #1
    robsmith is offline Advanced Beginner
    Windows 8 Access 2016
    Join Date
    Feb 2020
    Posts
    35

    Converting an Update Query to VBA

    Hi,



    I am trying to build an update query into some VBA code. I want to delete all test after the comma but I keep getting a syntax error.

    Can anyone see the problem?

    Code:
    CurrentDb.Execute "UPDATE Matches SET Matches.Toss = Left([Matches.Toss], InStr([Matches.Toss], ", ") - 1) WHERE Matches.Toss Like "*, *"", dbFailOnError
    Thanks

  2. #2
    Minty is offline VIP
    Windows 10 Office 365
    Join Date
    Sep 2017
    Location
    UK - Wiltshire
    Posts
    3,157
    Put you sql into a string an debug.print it - the error will be obvious;

    Code:
    Dim strSQL as String
    
    strSQL = "UPDATE Matches SET Matches.Toss = Left([Matches.Toss], InStr([Matches.Toss], ", ") - 1) WHERE Matches.Toss Like "*, *""
    
    Debug.Print strSQL
    CurrentDb.Execute strSQL, dbFailOnError
    Press ctrl+g to show the immediate window in the VBA editor it will display your string.

    I suspect it should be something like

    strSQL = "UPDATE Matches SET Matches.Toss = Left([Matches.Toss], InStr([Matches.Toss], ', ') - 1) WHERE Matches.Toss Like '*, *'"


    DLookup Syntax and others http://access.mvps.org/access/general/gen0018.htm
    Please use the star below the post to say thanks if we have helped !
    ↓↓ It's down here ↓↓

  3. #3
    robsmith is offline Advanced Beginner
    Windows 8 Access 2016
    Join Date
    Feb 2020
    Posts
    35
    Thanks Minty

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

Similar Threads

  1. Help - Converting a SQL Query into Access
    By paularthur09 in forum Queries
    Replies: 3
    Last Post: 01-20-2016, 09:38 AM
  2. Help Converting Oracle PL/SQL Query into Access
    By RThomas321 in forum Queries
    Replies: 5
    Last Post: 11-15-2014, 12:35 PM
  3. converting number into words in query
    By joshynaresh in forum Queries
    Replies: 3
    Last Post: 04-02-2014, 08:17 PM
  4. Converting Scientific notation in a Query
    By wuhsean22 in forum Queries
    Replies: 2
    Last Post: 02-06-2013, 05:30 PM
  5. Replies: 1
    Last Post: 09-12-2011, 10:22 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