Results 1 to 3 of 3
  1. #1
    WickidWe is offline Competent Performer
    Windows 7 64bit Access 2010 32bit
    Join Date
    Nov 2013
    Posts
    123

    Delete query works in Access but not when I try to run with VBA

    My Working Query In VBA


    Code:
    DELETE *
    FROM tblRosterRec
    WHERE ID <>  (SELECT Max(ID) AS MaxOfID FROM  tblRosterRec AS Dupe      
       WHERE (Dupe.EmpID =  tblRosterRec.EmpID)                         
       AND (Dupe.Date_ =  tblRosterRec.Date_));
    My VBA Code (not working)"
    Code:
    Dim sSQL As String
    sSQL = "DELETE * " & _
    "FROM tblRosterRec " & _
    "WHERE ID <>  (SELECT Max(ID) AS MaxOfID FROM  tblRosterRec AS Dupe" & _
    "WHERE (Dupe.EmpID =  tblRosterRec.EmpID)" & _
    "AND (Dupe.Date_ =  tblRosterRec.Date_));"
    CurrentDb.Execute (sSQL)
    Error:
    Click image for larger version. 

Name:	debug.png 
Views:	8 
Size:	17.8 KB 
ID:	15078

  2. #2
    WickidWe is offline Competent Performer
    Windows 7 64bit Access 2010 32bit
    Join Date
    Nov 2013
    Posts
    123
    sorted myself
    I missed the space before " & _

  3. #3
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,622
    Statement run-on - missing a space between: AS DupeWHERE

    Put a space in the code: AS Dupe "
    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.

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

Similar Threads

  1. Replies: 2
    Last Post: 11-21-2013, 10:40 AM
  2. Access 2010 Delete Query Question
    By scheibla in forum Queries
    Replies: 3
    Last Post: 05-01-2012, 08:34 PM
  3. Delete Query Access SQL
    By tlindeman in forum Queries
    Replies: 1
    Last Post: 05-01-2012, 12:14 PM
  4. Replies: 3
    Last Post: 03-15-2012, 03:42 PM
  5. Replies: 2
    Last Post: 01-24-2012, 02:16 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